0

嘿,这是我的要求。

我需要检查一列是否为空,如果需要返回“MISSING”,否则为空刺。

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 语句。

4

3 回答 3

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 ...
于 2013-09-04T21:26:35.457 回答
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
于 2013-09-04T21:29:48.980 回答
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 ...
于 2013-09-04T22:02:40.583 回答