Hi,
does anyone know how to convert character field to numeric in db2 udb. My problem is the thousand separator period(.) I can use translate function to get rid off the period but it doesn't help much.
Hi Greg,
yep, I have tried dec function but maybe I haven't found the proper syntax. The char value is:'10.233,50'. and when I use dec function I get error. Maybe I should first split the value from left and right of the period and then concat them again and then use dec to get it decimal?
If this is for one value, then why not concatenate 2 substrings (making sure you get rid of the '.') and converting the resulting string with the DEC function...?
it's a little long winded, but you could try the following (assuming in this case your value is in a field called CHAR_10):
SELECT DEC(STRIP(TRANSLATE(SUBSTR(CHAR_10,1,2),' ','.'),B)
|| STRIP(TRANSLATE(SUBSTR(CHAR_10,3,2),' ','.'),B)
|| STRIP(TRANSLATE(SUBSTR(CHAR_10,5,2),' ','.'),B)
|| STRIP(TRANSLATE(SUBSTR(CHAR_10,7,2),' ','.'),B)
|| STRIP(TRANSLATE(SUBSTR(CHAR_10,9,2),' ','.'),B),10,2)
This takes the string a pair of characters at a time, converts '.' to a space, and then trims off any spaces at either end, concatenates them all together and finally converts to a decimal (10,2)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.