根据条件提取'列名'

时间:2017-09-06 11:46:46

标签: sql oracle oracle-sqldeveloper

我有一个名为Employee的表,其中包含字段 Id,地址,phone_no,薪水,date_of_joining 。它只包含一行和字段:

  • ID,工资填充了值
  • 地址,phone_no date_of_joining 包含NULL个值。

我希望输出为包含NULL值的字段,即地址 phone_no date_of_joining 。这需要在Oracle SQL中执行。我不知道如何去做。

输入:

EMPLOYEE                    
Id    Address   phone_no    salary      date_of_joining   stream
101   NULL      NULL        8,00,000    NULL              Big Data

输出:

Address,
phone_no,
date_of_joining

2 个答案:

答案 0 :(得分:1)

您可以明确地执行此操作:

select 'Id' from t where Id is null union all
select 'Address' from t where Address is null union all
select 'phone_no' from t where phone_no is null union all
select 'salary' from t where salary is null union all
select 'date_of_joining' from t where date_of_joining is null union all
select 'stream' from t where stream is null;

答案 1 :(得分:0)

你可以这样做(与戈登的解决方案相同,但在一个记录中):

Select Id,
case when phone_no is null then 'phone_no, ' else '' end || 
case when Address is null then 'Address, ' else '' end ||
case when date_of_joining is null then 'date_of_joining' else '' end as Null_values
from t;