日期:2014-05-17 浏览次数:20801 次
with a as(
select 1 id,'E' type,'AA' name from dual
union all
select 2,'F',null from dual
),b as(
select 1 id, 2 aid, 'BB' name from dual
union all
select 2,2,'CC' from dual
)
select a.id, a.type, wm_concat(nvl(a.name, b.name))
from a, b
where a.id = b.aid(+)
group by a.id, a.type;
ID TYPE WM_CONCAT(NVL(A.NAME,B.NAME))
---------- ---- --------------------------------------------
1 E AA
2 F BB,CC
WITH TABLE1 AS(
SELECT '1' AS Aid, 'E' AS type,'AA' as name FROM dual
union all
SELECT '2' AS Aid, 'F' AS type,'' as name FROM dual
union all
SELECT '3' AS Aid, 'F' AS type,'' as name FROM dual
union all
SELECT '4' AS Aid, 'A' AS type,'FF' as name FROM dual
),
TABLE2 AS (
SELECT '1' AS id, '2' AS Aid,'BB' as name FROM dual
union all
SELECT '2' AS id, '2' AS Aid,'CC' as name FROM dual
union all
SELECT '3' AS id, '3' AS Aid,'DD' as name FROM dual
union all
SELECT '4' AS id, '3' AS Aid,'EE' as name FROM dual
)
SELECT T1.Aid,
T1.TYPE,
LISTAGG(nvl(T1.NAME, T2