I’m having trouble with TO_NUMBER function second and third parameters. Does one of them depend on the other one? How does nls_params parameter work? I can’t understand how the the result of the query
SELECT TO_NUMBER('17.000,23',
'999G999D99',
'nls_numeric_characters='',.'' ')
REFORMATTED_NUMBER
FROM DUAL;
can be 17000.23. Could somebody please explain the process of the above conversion.
P.S. The above query is taken from an Oracle Database SQL Expert Certificate preparation book.
Now, I’ll answer my own question. While using
TO_NUMBERfunction I missed the important point that, whatever I get fromTO_NUMBERfunction is going to be a number. And a number does not include anything else than decimal point and E scientific notation. So 17,788.99 is not actually a number but is rather the string representation of 17788.99.If we try to subtract 500 from 17,788.99 we’ll fail.(Well, Oracle implicitly converts numeric strings to numbers and vice-versa, but principally we can’t perform arithmetic operations between strings and numbers). I’m sure that
TO_NUMBERfunction is almost never used to select a column value. It’s rather used to be able to make arithmetic operations. Instead, we useTO_CHARto show a column value or any numeric expression in a neat, easy to read format. The fomat models and nls_params are not only forTO_NUMBERfunction, but forTO_CHARas well.