views:

34

answers:

2

I have data like this in oracle database -> 20123,45 ,data type is varchar. and I want to migrate it to column with NUMBER data type, change comma (,) to dot (.). so expected result is 20123.45 and data type is NUMBER,

how can I do that ?

thanks before :D

+3  A: 

use

to_number(YourColumnName, FormatMask, NLS_NUMERIC_CHARACTERS = ',.') from ...

select to_number('12345.667677', '99999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''') 
from dual

select to_number('12345,667677', '99999999D999999', 'NLS_NUMERIC_CHARACTERS = '',.''') 
from dual
Michael Pakhantsov
aldi
@aldi, make you format mask as long as you need. for instance '999999999999999999999999D9999999999999999999'
Michael Pakhantsov
oke,,its work Michael, thanks, but when I use ColumnName, there is an error, : invalid sql statement, but when I use hardcoded value, its work, any idea ?
aldi
@aldi, may you show part of your query? some value from ColumnName, Format mask and NLS settings
Michael Pakhantsov
oke Michael, it was because the FormatMask length I used less then my data length :) , thanks for your answer :D
aldi
A: 

Another way to do this would be

SELECT TO_NUMBER(REPLACE('12345,6789123', ',', '.')) FROM DUAL;

Share and enjoy.

Bob Jarvis