0

我有包含员工详细信息的源表,我需要导出一个缺失信息表。带有缺失值列表。缺失的值可能是 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
4

2 回答 2

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

于 2013-10-10T00:12:38.410 回答
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

字符串聚合取自String Aggregation Techniques

于 2013-10-10T00:05:07.087 回答