[英]ORA-01722: invalid number - getting this error
我正在尝试在 oracle sql developer中执行以下操作
select code, case when (code = 'SS') then 1 else to_number(code) end as code_modified
from pxrptuser.WBS
但我收到错误。
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
输出应该是 -
code code_modified
D0DV-IMS null
gWBS null
8 8
1 1
SS 1
请帮助我进行实际查询
您的数据中有无法转换为数字的字符串(“SS”除外)。
从 Oracle 12.2 开始,您可以使用to_number()
的on conversion error
子句为无效值返回null
:
select code,
case
when code = 'SS' then 1
else to_number(code default null on conversion error)
end as code_modified
from pxrptuser.WBS
在早期版本中,一种替代方法是使用正则表达式。 如果您的数字没有小数部分,如您的数据所示,则更简单:
select code,
case
when code = 'SS' then 1
when not regexp_like(code, '\D') then to_number(code)
end as code_modified
from pxrptuser.WBS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.