with TMP_TABLE as
(
select 'A' as MATLOTID, 'AA' AS NEWVALUE from dual
union all
select 'A' as MATLOTID, 'AB' AS NEWVALUE from dual
union all
select 'A' as MATLOTID, 'AC' AS NEWVALUE from dual
union all
select 'AA' as MATLOTID, 'AA1' AS NEWVALUE from dual
union all
select 'AA1' as MATLOTID, 'AA11' AS NEWVALUE from dual
)
SELECT *
FROM TMP_TABLE
start with MATLOTID = 'A'
connect by nocycle prior NEWVALUE= MATLOTID
위 쿼리 결과.
MATLOTID | NEWVALUE |
A | AA |
AA | AA1 |
AA1 | AA11 |
A | AB |
A | AC |
[최종 결과]
RESULT |
A->AA->AA1->AA11 |
A->AB |
A->AC |
어떠한 방법으로 해야 결과값이 나올지 고수님들 부탁드립니다.ㅠ
with TMP_TABLE as ( select 'A' as MATLOTID, 'AA' AS NEWVALUE from dual union all select 'A' as MATLOTID, 'AB' AS NEWVALUE from dual union all select 'A' as MATLOTID, 'AC' AS NEWVALUE from dual union all select 'AA' as MATLOTID, 'AA1' AS NEWVALUE from dual union all select 'AA1' as MATLOTID, 'AA11' AS NEWVALUE from dual ) SELECT sys_connect_by_path(NEWVALUE,'>') , sys_connect_by_path(MATLOTID,'>') FROM TMP_TABLE start with MATLOTID = 'A' connect by nocycle prior NEWVALUE= MATLOTID