日期:2014-05-17 浏览次数:20728 次
SELECT T3.ID, LTRIM(MAX(SYS_CONNECT_BY_PATH(T3.NAME, ',')), ','), T3.MEMO
FROM (SELECT ROW_NUMBER() OVER(PARTITION BY T2.RNUM ORDER BY T1.NAME) RN,
T1.NAME,
T2.RNUM,
T2.ID,
T2.MEMO
FROM TB1 T1,
(SELECT T.ID,
T.RNUM,
REGEXP_SUBSTR(T.TB1ID, '[^,]+', 1, LEVEL) STR,
T.MEMO
FROM (SELECT T.ID, T.TB1ID, ROWNUM RNUM, T.MEMO FROM TB2 T) T
CONNECT BY LEVEL <=
(LENGTH(T.TB1ID) -
LENGTH(REPLACE(T.TB1ID, ',', ''))) / LENGTH(',') + 1
AND PRIOR RNUM = RNUM
&nb