日期:2014-05-16 浏览次数:21047 次
WITH A AS(
SELECT 1 AS TYPE,'NAME1' AS NAME,1 AS ID,'WC1' AS DES FROM DUAL UNION ALL
SELECT 2,'NAME2',2,'WC2' FROM DUAL UNION ALL
SELECT 3,'NAME3',3,'WC3' FROM DUAL UNION ALL
SELECT 4,'NAME4',4,'WC4' FROM DUAL
),B AS(
SELECT 1 AS ID,1 AS TYPE,'WC1' AS DES FROM DUAL UNION ALL
SELECT 2,2,'WC2' FROM DUAL UNION ALL
SELECT 3,2,'WC3' FROM DUAL UNION ALL
SELECT 4,4,'WC4' FROM DUAL
)
SELECT A.ID, A.NAME, WMSYS.WM_CONCAT(B.DES)
FROM A, B
WHERE A.TYPE = B.TYPE(+)
GROUP BY A.ID, A.NAME;
WITH A AS(
SELECT 1 AS TYPE,'NAME1' AS NAME,1 AS ID,'WC1' AS DES FROM DUAL UNION ALL
SELECT 2,'NAME2',2,'WC2' FROM DUAL UNION ALL
SELECT 3,'NAME3',3,'WC3' FROM DUAL UNION ALL
SELECT 4,'NAME4',4,'WC4' FROM DUAL
),B AS(
SELECT 1 AS ID,1 AS TYPE,'WC1' AS DES FROM DUAL UNION ALL
SELECT 2,2,'WC2' FROM DUAL UNION ALL
SELECT 3,2,'WC3' FROM DUAL UNION ALL
SELECT 4,4,'WC4' FROM DUAL
)
SELECT ID,NAME,LTRIM(MAX(SYS_CONNECT_BY_PATH(DES, ',')), ',') AS DES FROM
(
SELECT ROW_NUMBER() OVER(PARTITION BY A.ID ORDER BY NAME) R,A.ID,A.NAME,B.DES
FROM A, B
WHERE A.TYPE = B.TYPE(+)
)
START WITH R = 1
CONNECT BY PRIOR R=R-1
AND PRIOR ID =ID
GROUP BY ID,NAME
ORDER BY 1