Oracle:to_char(number) 的模式以添加额外的 ascii 字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/586088/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:44:18  来源:igfitidea点击:

Oracle: Pattern for to_char(number) to add additional ascii characters?

oracleformattingnumbersasciioracle-apex

提问by fdl

Using the Oracle to_char(number) function, is it possible to append ascii characters to the returned string?

使用 Oracle to_char(number) 函数,是否可以将 ascii 字符附加到返回的字符串?

Specifically, I need to add a percentage character to the returned string.

具体来说,我需要在返回的字符串中添加一个百分比字符。

"select to_char(89.2244, '999G999G999G999G990D00') from dual" --> returns "89.22". I need a format pattern that returns "89.22%".

"select to_char(89.2244, '999G999G999G999G990D00') from dual" --> 返回 "89.22"。我需要一个返回“89.22%”的格式模式。

I am using this through reports in Application Express, so cannot simply concatenate "%" to the query, i need to put it in the number format.

我通过 Application Express 中的报告使用它,所以不能简单地将“%”连接到查询,我需要将它放在数字格式中。

回答by Barry

So you can't wrap the to_char with a CONCAT?

所以你不能用 CONCAT 包装 to_char 吗?

select concat(to_char(89.2244, '999G999G999G999G990D00'),'%') from dual

回答by Quassnoi

You can't do it right in the number format.

你不能用数字格式正确地做到这一点。

If you are able to change NLS_CURRENCYfor you session, you can do the following:

如果您能够NLS_CURRENCY为您的会话进行更改,则可以执行以下操作:

SELECT  TO_CHAR(1.2, '999G999G999G999G990D00L' /*, 'NLS_CURRENCY=%' */)
FROM    dual

--- 
1,20%

回答by Juris

Quick and dirty way:

快速而肮脏的方式:

select to_char(89.2244, '999G999G999G999G990D00L', 'NLS_CURRENCY=''%''') from dual;

从双中选择 to_char(89.2244, '999G999G999G999G990D00L', 'NLS_CURRENCY=''%''');

回答by Paul

SYS @ orant11g >select to_char(89.2244, '999G999G999G999G990D00')||'%' from dual;
TO_CHAR(89.2244,'999G999
------------------------
              89.22%
TO_CHAR(89.2244,'999G999
------------------------
              89.22%

Just use the || bars instead of the concat function.

只需使用 || bar 而不是 concat 函数。