Guys i want to print the following data with comma separated values using oracle sql
696585242087
to
69,658,524,2087
and same for the decimal.
Guys i want to print the following data with comma separated values using oracle sql
696585242087
to
69,658,524,2087
and same for the decimal.
SELECT TO_CHAR(696585242087, '99G999G999G9999', 'NLS_NUMERIC_CHARACTERS=",."')
FROM dual
See the Oracle docs for all the insanity that can be done for number formatting. The short version is you need the "TO_CHAR" function, and provide a formatting string for the output:
TO_CHAR( col_name, '999,999,999,999')
Should do what you need.
Taking the Dead programmer's update (24/Jan/2011) (original author of the question) and the comment of Amir Pashazadeh (5/Mar/2016), we can get the desired comma separated format with the following example.
This code applies for numbers with equal or less than 15 digits, if you will need for bigger length, you should add more 999,999 according with the max of length you will manage.
SELECT TRIM(TO_CHAR(12345678, '999,999,999,999,999')) ttry FROM DUAL
UNION ALL
SELECT TRIM(TO_CHAR( 1234, '999,999,999,999,999')) ttry FROM DUAL
;