LEVEL | ID | PARENTID | NAME |
1 | 0000000101 | <NULL> | 루트 |
2 | 0000029474 | 0000000101 | [구2]BU |
3 | 0000030210 | 0000029474 | [O]D2S |
4 | 0000030218 | 0000030210 | Sales Environment Structure Improvement |
5 | 0000030222 | 0000030218 | 유통POG 미적용품목 |
5 | 0000030221 | 0000030218 | 유통POG 적용품목 |
5 | 0000030220 | 0000030218 | 진열관리 |
5 | 0000030219 | 0000030218 | 진열제안 |
4 | 0000030215 | 0000030210 | 프로모션관리 |
5 | 0000030217 | 0000030215 | 매장 |
5 | 0000030216 | 0000030215 | 유통본부 |
3 | 0000029735 | 0000029474 | [O]P2P |
4 | 0000029974 | 0000029735 | Vendor Management |
5 | 0000029975 | 0000029974 | [공통] 평가/운영/거래종료 |
4 | 0000029873 | 0000029735 | 조달구매 |
5 | 0000029937 | 0000029873 | 상품 조달 |
5 | 0000029936 | 0000029873 | 제품 조달 |
5 | 0000029919 | 0000029873 | 협력기업 원부재료 조달 |
2 | 0000021864 | 0000000101 | Japan BU |
3 | 0000029478 | 0000021864 | [M]T2R |
4 | 0000029479 | 0000029478 | 리스크대응 |
5 | 0000029505 | 0000029479 | [On-line] 리콜 |
5 | 0000029492 | 0000029479 | 미납/미출_단기 |
5 | 0000029484 | 0000029479 | 미납/미출 |
5 | 0000029483 | 0000029479 | 사고 |
5 | 0000029480 | 0000029479 | 안전 이슈 제기 |
3 | 0000029475 | 0000029474 | [L]S2S |
4 | 0000029476 | 0000029475 | Business Planning |
5 | 0000029477 | 0000029476 | 연간사업계획수립 |
2 | 0000018818 | 0000000101 | [구]한국BU2 |
3 | 0000019580 | 0000018818 | [O]D2S |
4 | 0000019585 | 0000019580 | Management |
5 | 0000019586 | 0000019585 | Promotion Management |
4 | 0000019581 | 0000019580 | Account Management |
5 | 0000019584 | 0000019581 | SL |
5 | 0000019583 | 0000019581 | KIDS |
레벨 | 계층명 |
2 | 계층1 |
4 | 항목1 |
2 | 계층2 |
4 | 항목2-1 |
4 | 항목2-2 |
2 | 계층3 |
4 | 항목3-1 |
4 | 항목3-2 |
4 | 항목3-3 |
위 데이터를 아래와 같이 나오게 하고 싶습니다.
계층1 계층2 계층3 계층4....
항목1 항목2-1 항목3-1 항목4-1....
항목2-2 항목3-2...
항목3-3
WITH t AS ( SELECT 1 lv, '0000000101' id, '' parentid, '루트' name FROM dual UNION ALL SELECT 2, '0000029474', '0000000101', '[구2]BU' FROM dual UNION ALL SELECT 3, '0000030210', '0000029474', '[O]D2S' FROM dual UNION ALL SELECT 4, '0000030218', '0000030210', 'Sales Environment Structure Improvement' FROM dual UNION ALL SELECT 5, '0000030222', '0000030218', '유통POG 미적용품목' FROM dual UNION ALL SELECT 5, '0000030221', '0000030218', '유통POG 적용품목' FROM dual UNION ALL SELECT 5, '0000030220', '0000030218', '진열관리' FROM dual UNION ALL SELECT 5, '0000030219', '0000030218', '진열제안' FROM dual UNION ALL SELECT 4, '0000030215', '0000030210', '프로모션관리' FROM dual UNION ALL SELECT 5, '0000030217', '0000030215', '매장' FROM dual UNION ALL SELECT 5, '0000030216', '0000030215', '유통본부' FROM dual UNION ALL SELECT 3, '0000029735', '0000029474', '[O]P2P' FROM dual UNION ALL SELECT 4, '0000029974', '0000029735', 'Vendor Management' FROM dual UNION ALL SELECT 5, '0000029975', '0000029974', '[공통] 평가/운영/거래종료' FROM dual UNION ALL SELECT 4, '0000029873', '0000029735', '조달구매' FROM dual UNION ALL SELECT 5, '0000029937', '0000029873', '상품 조달' FROM dual UNION ALL SELECT 5, '0000029936', '0000029873', '제품 조달' FROM dual UNION ALL SELECT 5, '0000029919', '0000029873', '협력기업 원부재료 조달' FROM dual UNION ALL SELECT 3, '0000029475', '0000029474', '[L]S2S' FROM dual UNION ALL SELECT 4, '0000029476', '0000029475', 'Business Planning' FROM dual UNION ALL SELECT 5, '0000029477', '0000029476', '연간사업계획수립' FROM dual UNION ALL SELECT 2, '0000021864', '0000000101', 'Japan BU' FROM dual UNION ALL SELECT 3, '0000029478', '0000021864', '[M]T2R' FROM dual UNION ALL SELECT 4, '0000029479', '0000029478', '리스크대응' FROM dual UNION ALL SELECT 5, '0000029505', '0000029479', '[On-line] 리콜' FROM dual UNION ALL SELECT 5, '0000029492', '0000029479', '미납/미출_단기' FROM dual UNION ALL SELECT 5, '0000029484', '0000029479', '미납/미출' FROM dual UNION ALL SELECT 5, '0000029483', '0000029479', '사고' FROM dual UNION ALL SELECT 5, '0000029480', '0000029479', '안전 이슈 제기' FROM dual UNION ALL SELECT 2, '0000018818', '0000000101', '[구]한국BU2' FROM dual UNION ALL SELECT 3, '0000019580', '0000018818', '[O]D2S' FROM dual UNION ALL SELECT 4, '0000019585', '0000019580', 'Management' FROM dual UNION ALL SELECT 5, '0000019586', '0000019585', 'Promotion Management' FROM dual UNION ALL SELECT 4, '0000019581', '0000019580', 'Account Management' FROM dual UNION ALL SELECT 5, '0000019584', '0000019581', 'SL' FROM dual UNION ALL SELECT 5, '0000019583', '0000019581', 'KIDS' FROM dual ) SELECT * FROM (SELECT lv , name , ROW_NUMBER() OVER(PARTITION BY lv, gb ORDER BY rn ) rn , DENSE_RANK() OVER(PARTITION BY lv ORDER BY gb DESC) dr FROM (SELECT name , LEVEL lv , ROWNUM rn , DECODE(LEVEL, 2, id, PRIOR parentid) gb FROM t WHERE LEVEL IN (2, 4) START WITH parentid IS NULL CONNECT BY PRIOR id = parentid AND LEVEL <= 4 ORDER SIBLINGS BY id DESC ) ) PIVOT (MIN(name) FOR dr IN (1, 2, 3, 4)) ORDER BY lv, rn ;