Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORACLE - String to number

I have a little problem with a column on a table. The column is a Varchar named "prize". The datas are something like:

00008599
00004565
00001600
etc...

They have to become:

85.99
45.65
16.00
etc...

I have tried with to_number function but it doesnt work. Something like:

SELECT to_number(prize, '999999.99') FROM TABLE

The error is: ORA-01722

like image 649
MrMime Avatar asked Oct 25 '12 09:10

MrMime


1 Answers

You could use LTRIM to get rid of leading zeroes and divide by 100:

SELECT to_number(ltrim(prize, '0')) / 100 FROM table
like image 180
Frank Schmitt Avatar answered Sep 28 '22 14:09

Frank Schmitt