我有源表,其中包含有关员工的详细信息,我需要派生一个缺失信息表。列表中缺少值。缺少的值可能是NULL或只是空的空格。
Source Table
**************
Name Age Gender Experience
-------------------------------------------------------------
David 22 M IT
John [NULL] M POLITICS
Judy 19 [NULL] [NULL]
Jasmine [NULL] [NULL] [NULL]
Target Table
**************
Name Missing_description
---------------------------------------------
John Missing Age
Judy Missing Gender, Experience
Jasmine Missing Age, Gender, Experience
答案 0 :(得分:1)
试
insert into TargetTable (name, description)
select name,'Missing'||description from (
select name, LISTAGG(descr, ', ') within group (order by descr) as description
from (
select name, 'age,' as descr from SourceTable where age is null
union all
select name, 'Gener,' from SourceTable where gender is null
union all
select name, 'Experience' from SourceTable where Experience is null
) as a
group by name) as b
http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php
答案 1 :(得分:0)
通过内存写入,现在没有安装oracle,但查询可以是这样的:
insert into TargetTable (name, description)
select name, LISTAGG(descr, ', ') within group (order by descr) as description
from (
select name, 'Missing age' as descr from SourceTable where age is null
union all
select name, 'Missing Gener' from SourceTable where gender is null
union all
...
) as a
group by name