我正在尝试在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请帮助我完成实际的查询
发布于 2020-11-06 08:31:42
您的数据中有无法转换为数字的字符串(“SS”除外)。
从Oracle12.2开始,您可以使用on conversion error子句to to_number()为无效值返回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.WBShttps://stackoverflow.com/questions/64707166
复制相似问题