XML 함수 사용하면 결과가 이상해서 올려봅니다. (버전 12C) WITH A_TBL AS ( SELECT 'A' CD FROM DUAL UNION ALL SELECT 'E' CD FROM DUAL UNION ALL SELECT 'C' CD FROM DUAL UNION ALL SELECT 'B' CD FROM DUAL UNION ALL SELECT 'D' CD FROM DUAL ), B_TBL AS ( SELECT 'B' CD ,'BB' DT FROM DUAL UNION ALL SELECT 'D' CD ,'DD' DT FROM DUAL UNION ALL SELECT 'C' CD ,'BB' DT FROM DUAL ), C_TMP AS ( SELECT A.* ,( -- A.CD를 1 LEVEL 참조 SELECT DT FROM B_TBL WHERE CD = A.CD AND ROWNUM = 1 ) AA ,( -- A.CD를 2 LEVEL 참조 SELECT DT FROM ( SELECT DT FROM B_TBL WHERE CD = A.CD AND ROWNUM = 1 ) ) BB ,( SELECT SUBSTR(XMLAGG(XMLELEMENT(A, LEVEL) ORDER BY 1).EXTRACT('//text()') ,1) FROM DUAL CONNECT BY LEVEL <=3 ) XAGG FROM A_TBL A ) SELECT * FROM C_TMP ORDER BY 1 결과 CD AA BB XAGG A 123 B BB BB 123 C BB BB 123 D DD DD 123 E 123 ---------------- SELECT * FROM C_TMP WHERE AA = 'BB' -- 1 LEVEL 참조필드 ORDER BY 1 결과 CD AA BB XAGG B BB BB 123 C BB BB 123 ---------------- SELECT * FROM C_TMP WHERE BB = 'BB' -- 2 LEVEL 참조필드 조건 안먹힘 ORDER BY 1 결과 CD AA BB XAGG ---------------- XML 함수 ,( SELECT SUBSTR(XMLAGG( .... ) XAGG 를 빼고 하면 2 LEVEL 참조필드 조건 먹힘 SELECT * FROM C_TMP WHERE BB = 'BB' -- 2 LEVEL 참조필드 조건 먹힘 ORDER BY 1 결과 CD AA BB B BB BB C BB BB