SQL oracle sql查询以逗号格式化数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4783760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
oracle sql query to format number by comma
提问by Dead Programmer
Guys i want to print the following data with comma separated values using oracle sql
伙计们,我想使用 oracle sql 用逗号分隔值打印以下数据
696585242087
to
69,658,524,2087
and same for the decimal.
和小数点一样。
回答by Quassnoi
SELECT TO_CHAR(696585242087, '99G999G999G9999', 'NLS_NUMERIC_CHARACTERS=",."')
FROM dual
回答by Herb
See the Oracle docsfor 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:
请参阅Oracle 文档,了解可以对数字格式进行的所有操作。简短版本是您需要“TO_CHAR”函数,并为输出提供格式化字符串:
TO_CHAR( col_name, '999,999,999,999')
Should do what you need.
应该做你需要的。
回答by neil
take a look to to_char: http://www.oradev.com/oracle_number_format.jsp
看看to_char:http: //www.oradev.com/oracle_number_format.jsp
回答by OscarSosa
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.
以死程序员的更新(24/Jan/2011)(问题的原作者)和Amir Pashazadeh的评论(5/Mar/2016),我们可以通过以下示例获得所需的逗号分隔格式。
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.
此代码适用于等于或小于 15 位的数字,如果您需要更大的长度,则应根据您将管理的最大长度添加更多 999,999。
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
;