Oracle 的 to_number - 怎么了?

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

Oracle's to_number - What's wrong?

sqloracle

提问by Ariod

What is wrong with the below format specifier for to_number?

下面的 to_number 格式说明符有什么问题?

SELECT TO_NUMBER('0,22', '0,99') * 100 FROM DUAL;

The result is 2200 instead of 22 -- what am I doing wrong?

结果是 2200 而不是 22——我做错了什么?

回答by Andomar

Try:

尝试:

TO_NUMBER('0,22', '9D99')

Unlike a literal comma, the Dwill only match the decimal separator. So if this fails, your decimal separator is probably a ., not a ,.

与文字逗号不同, theD将只匹配小数点分隔符。所以如果这失败了,你的小数点分隔符可能是 a .,而不是 a ,

You can use this command to see the decimal separator and the thousand separator:

您可以使用此命令查看小数点分隔符和千位分隔符:

select value from nls_session_parameters
where parameter = 'NLS_NUMERIC_CHARACTERS'

If this returns .,, the comma is your thousand separator.

如果返回.,,则逗号是千位分隔符。

To change the separator for a single query, you could:

要更改单个查询的分隔符,您可以:

select TO_NUMBER('0,22','9D99','nls_numeric_characters=,.') from dual;

回答by juFo

A quick guess: 0.22 versus 0,22 (same for 9.99 versus 0,99 )

快速猜测: 0.22 与 0,22 (相同 9.99 与 0,99 )

?

?