6

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?

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Law
  • 349
  • 2
  • 5
  • 14

3 Answers3

9

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

Captain
  • 2,148
  • 15
  • 13
5

This can be used as well since the decimal notation is already know for French countries

SELECT TO_CHAR(1000000000,'999,999,999,999.99') "Amount"  FROM DUAL;
Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
Solami
  • 51
  • 1
  • 1
2

As one of the options, you can set NLS_TERRITORY parameter at a session level:

alter session set nls_territory='FRANCE';

select to_char(10000, 'fm99G999D00') as french
  from dual;

Result:

FRENCH   
----------
10 000,00 


alter session set nls_territory='SWITZERLAND';

select to_char(10000, 'fm99G999D00') as switzerland
  from dual

Result:

SWITZERLAND
-----------
10'000.00
Nick Krasnov
  • 26,886
  • 6
  • 61
  • 78