我需要检查一个列是否为null如果是这样我需要返回'MISSING',否则为空sting。
Column1(PrimaryKey) COLUMN2 COLUMN3
P1 ABC DEF
P2 NULL KJL
P3 NULL NULL
结果应该是
COLUMN1 RESULT
P1 ''
P2 MISSINGCOLUMN2
P3 MISSINGCOLUMN3,COLUMN2
我尝试使用CONCAT('MISSING',NVL(COLUMN2,'COLUMN2')) - 如果值为NULL,则其工作但在有效值的情况下,它将重新生成有效值;因为我们无法将3个参数传递给NVL语句。
答案 0 :(得分:0)
您可以尝试类似
的内容select Column1,
case
when Column2 is null and Column3 is null then 'MISSINGCOLUMN3,COLUMN2'
when Column2 is null then 'MISSINGCOLUMN2'
when Column3 is null then 'MISSINGCOLUMN3'
else ' '
end
from ...
答案 1 :(得分:0)
select column1, CASE
WHEN
Column2 is null and column3 is not null
then
'MISSING COLUM2'
WHEN
Column3 is null and column2 is not null
then
'MISSING COLUM3'
WHEN
Column3 is null and column2 is null
then
'MISSING COLUM3, column2'
WHEN
Column3 is not null and column2 is not null
then
''''
end as result
from table
答案 2 :(得分:0)
SELECT "COLUMN1",
(case when "COLUMN2" is null or "COLUMN3" is null then 'MISSING' else '' end)
||
(case when "COLUMN3" is null then 'COLUMN3' else '' end)
||
(case when "COLUMN2" is null and "COLUMN3" is null then ',' else '' end)
||
(case when "COLUMN2" is null then 'COLUMN2' else '' end) as RESULT
FROM ...