PL SQL:NVL 第一个参数类型转换问题
我有一个表应用程序,其中有一列
BORROWINGTERM NUMBER(10,0) Nullable
为什么此脚本会抛出错误(ORA-01722 无效数字),
select nvl(borrowingterm, 'no term') from Application
而这个脚本可以工作
select nvl(to_char(borrowingterm), 'no term') from Application
,并且这个脚本也可以
select nvl(1234,5678) from dual;
基于 本文
NVL函数的第一个参数应该是字符串类型
I have a table Application which has a column
BORROWINGTERM NUMBER(10,0) Nullable
why this script throw an error (ORA-01722 invalid number)
select nvl(borrowingterm, 'no term') from Application
while this one works
select nvl(to_char(borrowingterm), 'no term') from Application
and this one also works
select nvl(1234,5678) from dual;
base on this article
the first parameter of NVL function should be string type
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您收到错误是因为您在 nvl 子句中混合了两种不同的类型。一个数字,一根字符串。类型必须相同。
You're getting the error because you are mixing two different types in the nvl clause. One number, one string. The types must be the same.
简单来说,
示例:
//将数字转换为字符串,然后向列提供字符串替换值
// 将 null 替换为 0
Keeping it simple ,
Example:
//conert number to string and then provide string substitute value to column
// replacing null with 0
简而言之,如果第一个参数是数字,那么 Oracle 会尝试将第二个参数转换为数字。
请参阅 NVL 文档
http://download.oracle。 com/docs/cd/B19306_01/server.102/b14200/functions105.htm#i91798
In short, if the first argument is numeric then Oracle attempts to convert the second argument to a number.
See NVL documentation
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions105.htm#i91798
在第一个示例中,由于
borrowingterm
是数字类型,Oracle 尝试将字符串“no term”隐式转换为数字,因此出现错误。请参阅 NVL 文档。
In your first example, because
borrowingterm
is a numeric type, Oracle is trying to implicitly convert the string 'no term' to a numeric, hence the error.See the NVL documentation.
我想你自己已经给出了答案。如果你问为什么,你应该考虑在另一个函数中重用NVL的输出类型的可能性。
在上面的情况下,nvl的输出是未知的,因此ORA -01722 被提出。
I think you gave the answer yourself. If you are asking why, you should consider the possibility of reusing the output type of NVL in another function.
In the situation above, the output of nvl is unknown, thus an ORA-01722 is raised.