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?
In SQL Server, you can use the T-SQL FORMAT() function to format a number as a currency. The FORMAT() function allows you to format numbers, dates, currencies, etc. It accepts three arguments; the number, the format, and an optional “culture” argument.
TO_CHAR(expression,format) converts a date, time, timestamp (date and time), or number expression to a character string according to the specified format string.
SQL Server has separate functions for YEAR() , MONTH() , and DAY() . Oracle uses TO_CHAR() ; SQL Server uses CONVERT() . One option is to define the functions YEAR() , MONTH() , and DAY() in Oracle and then use string concatenation (via the CONCAT() ) function to combine the data.
The FORMAT() function formats a number to a format like "#,###,###. ##", rounded to a specified number of decimal places, then it returns the result as a string.
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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With