根据多列 是否为空, update一个结果列
举个例子:
一个表 有 a b c d 和 result列
现在想根据 a b c d是否为空,update这个表的result列
比如 全空 将result列更新为 0000
ad空 b c不空 result就是0110
abcd都有值 result就是1111
能不能用一次执行就办到呢?
想起来一个 update table set result=NVL2(a,0,1)||NVL2(b,0,1)||NVL2(c,0,1)||NVL2(d,0,1)
还不知道可以不。
gygy111
10 years, 10 months ago
Answers
update t_test111
set result = case when a is null and d is null and b is not null and c is not null then '0110'
when a is null and d is null and b is null and c is null then '0000'
when a is not null and d is not null and b is not null and c is not null then '1111'
end
;
nibhao
answered 10 years, 10 months ago