sql - How add separating blank space in numeric value -
unfortunately couldn't find solutions in docs.
i want numbers in specific format, this:
234652.24 --> 234 652.24 42145124 --> 42 145 124 select employee_id, to_char(salary, '??????') "salary employees;
you can specify the nls_numeric_chartacters
setting part of the to_char()
call, , use g
, d
format model placeholders:
with employees (employee_id, salary) ( select 1, 234652.24 dual --> 234 652.24 union select 2, 42145124 dual --> 42 145 124 ) select employee_id, to_char(salary, '999g999g999d99', 'nls_numeric_characters=''. ''') "salary" employees; employee_id salary ----------- --------------- 1 234 652.24 2 42 145 124.00
if don't want trailing zeros in second value can add fm format modifier, removes leading space (which there allow minus sign if there negative values); still leaves trailing period; can use rtrim()
rid of that:
with employees (employee_id, salary) ( select 1, 234652.24 dual --> 234 652.24 union select 2, 42145124 dual --> 42 145 124 ) select employee_id, rtrim(to_char(salary, 'fm999g999g999d99', 'nls_numeric_characters=''. '''), '.') "salary" employees; employee_id salary ----------- --------------- 1 234 652.24 2 42 145 124
Comments
Post a Comment