逐个更新ORA-01722无效编号

时间:2015-03-11 16:39:04

标签: sql oracle sql-update

我正在尝试根据其他两列的值更新表格列。

出于某种原因,我收到了ORA-01722:无效号码

UPDATE TableT SET 
   Col = (CASE when PER in ('1234','2134','2314','3214') AND TYPE = 4 then '4' 
                     when PER in ('34','104','1004') AND TYPE = 4 then '35' 
                     when PER in ('124','1204','2014') AND TYPE = 4  then '36'
               ELSE 'Missing'  
END);

1 个答案:

答案 0 :(得分:2)

ORA-01722此语句失败的唯一方法是Col是数字列。 '4''35''36'可以自动转换为数字。但是,如果没有满足case条件,并且您最终评估else分支,则它将返回无法转换为数字的字符串Missing

处理它的一种方法可能是使用null,它旨在代表缺失值:

UPDATE TableT SET 
   Col = (CASE when PER in ('1234','2134','2314','3214') AND TYPE = 4 then 4 
                     when PER in ('34','104','1004') AND TYPE = 4 then 35 
                     when PER in ('124','1204','2014') AND TYPE = 4  then 36
               ELSE NULL  
          END);