Oracle to_number函数参数

发布于 2024-12-12 03:14:39 字数 342 浏览 0 评论 0原文

我在使用 TO_NUMBER 函数的第二个和第三个参数时遇到问题。其中一项是否依赖于另一项? nls_params 参数如何工作?我不明白查询结果怎么

SELECT TO_NUMBER('17.000,23', 
             '999G999D99', 
             'nls_numeric_characters='',.'' ')  
             REFORMATTED_NUMBER 
FROM   DUAL; 

会是17000.23。有人可以解释一下上述转换的过程吗?

PS 上面的查询摘自一本Oracle数据库SQL专家证书准备书。

I'm having trouble with TO_NUMBER function second and third parameters. Does one of them depend on the other one? How does nls_params parameter work? I can't understand how the the result of the query

SELECT TO_NUMBER('17.000,23', 
             '999G999D99', 
             'nls_numeric_characters='',.'' ')  
             REFORMATTED_NUMBER 
FROM   DUAL; 

can be 17000.23. Could somebody please explain the process of the above conversion.

P.S. The above query is taken from an Oracle Database SQL Expert Certificate preparation book.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2024-12-19 03:14:39

您告诉 TO_NUMBER 函数,
nls_numeric_characters 中的两个字符 ,. 代表小数点和千位分隔符

G (thousands seperator) = .
D (decimal seperator)   = ,

,因此它将数字视为一万七千点二十三分。

请参阅:http://download.oracle.com/docs/cd/B13789_01/olap.101/b10339/x_stddev022.htm#i78653

you are telling the TO_NUMBER function that,
the two characters ,. in nls_numeric_characters represent the decimal and thousand seperator

G (thousands seperator) = .
D (decimal seperator)   = ,

so it sees the number as seventeen thousand point twenty three.

see: http://download.oracle.com/docs/cd/B13789_01/olap.101/b10339/x_stddev022.htm#i78653

深海少女心 2024-12-19 03:14:39

现在,我将回答我自己的问题。在使用 TO_NUMBER 函数时,我错过了重要的一点:无论我从 TO_NUMBER 函数得到什么,都将是一个数字。数字除了小数点和 E 科学计数法外不包含任何其他内容。因此 17,788.99 实际上并不是一个数字,而是 17788.99 的字符串表示形式。

如果我们尝试从 17,788.99 中减去 500,我们就会失败。(嗯,Oracle 隐式地将数字字符串转换为数字,反之亦然,但原则上我们不能在字符串和数字之间执行算术运算)。我确信 TO_NUMBER 函数几乎从未用于选择列值。它更适合进行算术运算。相反,我们使用 TO_CHAR 以简洁、易于阅读的格式显示列值或任何数字表达式。格式模型和 nls_params 不仅适用于 TO_NUMBER 函数,也适用于 TO_CHAR

Now, I'll answer my own question. While using TO_NUMBER function I missed the important point that, whatever I get from TO_NUMBER function is going to be a number. And a number does not include anything else than decimal point and E scientific notation. So 17,788.99 is not actually a number but is rather the string representation of 17788.99.

If we try to subtract 500 from 17,788.99 we'll fail.(Well, Oracle implicitly converts numeric strings to numbers and vice-versa, but principally we can't perform arithmetic operations between strings and numbers). I'm sure that TO_NUMBER function is almost never used to select a column value. It's rather used to be able to make arithmetic operations. Instead, we use TO_CHAR to show a column value or any numeric expression in a neat, easy to read format. The fomat models and nls_params are not only for TO_NUMBER function, but for TO_CHAR as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文