Search code examples
sqloracle-databasecurrencyto-char

SQL to_char Currency Formatting


I am facing a to_char() currency formatting problem here.

The below code is working for me:

SELECT TO_CHAR(10000,'L99G999D99MI',
               'NLS_NUMERIC_CHARACTERS = ''.,''
               NLS_CURRENCY = $') "Amount"
  FROM DUAL; 

which will provide me with the output: $10,000.00.
Now, I want to convert the currency into a France currency, which the desire output is 10 000,00 or a Switzerland currency with output 10'000.00. So, I modified the code as shown below for both of the case above:

SELECT TO_CHAR(10000,'L99G999D99MI',
               'NLS_NUMERIC_CHARACTERS = ''"", ""''
               NLS_CURRENCY = ''$'' ') "Amount"
  FROM DUAL;


SELECT TO_CHAR(10000,'L99G999D99MI',
               'NLS_NUMERIC_CHARACTERS = ''". "''
               NLS_CURRENCY = ''$'' ') "Amount"
  FROM DUAL;

But this code does not work and showing an error of ORA-12702. Is there any problem with the code?


Solution

  • If you want to do it in the query:

    SELECT TO_CHAR(10000,'L99G999D99MI',
               'NLS_NUMERIC_CHARACTERS = ''.''''''
               NLS_CURRENCY = ''$'' ') "Amount"
               FROM DUAL;
    

    Gives $10'000.00 (as this string is getting pre-processed there are pairs of quotes around the characters (becoming single) and then to get a single-quote in the string you need four quotes to become one!)

    SELECT TO_CHAR(10000,'L99G999D99MI',
               'NLS_NUMERIC_CHARACTERS = '', ''
               NLS_CURRENCY = ''$'' ') "Amount"
               FROM DUAL;
    

    Gives $10 000,00