■ START WITH ~ CONNECT BY PRIOR 절을 사용해 재귀 호출하는 방법을 보여준다.
▶ 예제 코드 (SQL)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
CREATE TABLE MENU ( ID INT ,PARENT_ID INT ,NAME VARCHAR(50) ); INSERT INTO MENU VALUES (1, 0, '메뉴1'); INSERT INTO MENU VALUES (2, 0, '메뉴2'); INSERT INTO MENU VALUES (3, 1, '메뉴3'); INSERT INTO MENU VALUES (4, 1, '메뉴4'); INSERT INTO MENU VALUES (5, 1, '메뉴5'); INSERT INTO MENU VALUES (6, 5, '메뉴6'); INSERT INTO MENU VALUES (7, 2, '메뉴7'); INSERT INTO MENU VALUES (8, 2, '메뉴8'); SELECT NAME, LTRIM(SYS_CONNECT_BY_PATH(NAME, ' > '), ' > ') AS TREE_PATH FROM MENU START WITH PARENT_ID = 0 CONNECT BY PRIOR ID = PARENT_ID; |