Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I change 1.234.56 value to 1234,56

Is there any way?

What I have tried:

I didn't find any solution on my own.
Posted
Updated 16-Feb-22 10:35am
v2
Comments
Maciej Los 14-Feb-22 16:33pm    
2 dots?
[EDIT]
How many dots can string contain? Only 2 or more?
I'd suggest to improve your question and provide more samples.

1 solution

To convert a string to a number in Oracle you use the Oracle / PLSQL: TO_NUMBER Function[^] (Try using your favourite search engine with the phrase "oracle convert string to number")

Your problem, as Maciej has pointed out, is that "1.234.56" is not a valid number in any culture that I am aware of. You would first need to remove that first period, and you can do that with REGEXP_REPLACE[^]

If it was meant to be "1,234.56" or "1.234,56" (German) or "1 234.56" (Swedish) then Oracle will still not recognise it as a number unless you do something about Globalisation - see Globalization Support[^]

Here is some sample code that demonstrates what might need to be done
SQL
with exampleData as (
  select '1.234.56' col1 from dual union all
  select '1234.56'  col1 from dual union all
  select '1 234.56'  col1 from dual union all
  select '1,234.56' col1 from dual 
)
select 
  case when length(col1) - length(replace(col1,'.',null)) > 1 
      then TO_NUMBER(regexp_replace(col1,'\.','',1,1))
  when length(col1) - length(replace(col1,',',null)) > 0 
      then TO_NUMBER(regexp_replace(col1,'\,','',1,1))
      -- Assuming not German!
  when length(col1) - length(replace(col1,' ',null)) > 0 
      then TO_NUMBER(regexp_replace(col1,' ','',1,1))
      -- Assuming not Swedish!
  else
      TO_NUMBER(col1) 
  end cnvrted
from exampleData;
 
Share this answer
 
Comments
Maciej Los 15-Feb-22 10:29am    
Excellent!
CHill60 15-Feb-22 10:31am    
Thank you Maciej!
Member 14588284 8-Mar-22 0:13am    
Thanks for answer :)
But codes turn "no results"
CHill60 8-Mar-22 1:40am    
My code returned the expected results when I tested it. Which value is not being returned?
CHill60 8-Mar-22 3:13am    
Ok. I just tested this again and it worked fine. If your code is not working then share it here and I will try to help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900