오라클 connect by 예제
connecty by 사용 전
WITH A AS(
SELECT 'A' AS CODE, '' AS P_CODE , '인사팀' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'B' AS CODE, '' AS P_CODE , '재무팀' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'C' AS CODE, '' AS P_CODE , '삽질팀' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'D' AS CODE, 'A' AS P_CODE , '김우진' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'E' AS CODE, 'B' AS P_CODE , '이동수' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'F' AS CODE, 'C' AS P_CODE , '이진수' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'G' AS CODE, 'C' AS P_CODE , '조둔서' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'H' AS CODE, 'B' AS P_CODE , '개뿔딱' AS TEAM_NAME FROM DUAL
)
SELECT A.*
FROM A;
connecty by 사용 후
WITH A AS(
SELECT 'A' AS CODE, '' AS P_CODE , '인사팀' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'B' AS CODE, '' AS P_CODE , '재무팀' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'C' AS CODE, '' AS P_CODE , '삽질팀' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'D' AS CODE, 'A' AS P_CODE , '김우진' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'E' AS CODE, 'B' AS P_CODE , '이동수' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'F' AS CODE, 'C' AS P_CODE , '이진수' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'G' AS CODE, 'C' AS P_CODE , '조둔서' AS TEAM_NAME FROM DUAL
UNION ALL
SELECT 'H' AS CODE, 'B' AS P_CODE , '개뿔딱' AS TEAM_NAME FROM DUAL
)
SELECT CODE,P_CODE,LPAD(' ', 8 * (LEVEL-1))||TEAM_NAME
FROM A
START WITH P_CODE IS NULL
CONNECT BY PRIOR CODE = P_CODE;
'-=-= 컴퓨터 =-=- > Database' 카테고리의 다른 글
java.sql.SQLException: 논리적 핸들이 더 이상 유효하지 않습니다 (0) | 2013.03.11 |
---|---|
오라클 split 함수 (0) | 2013.02.20 |
오라클 리스너 로그 설정 해제 (0) | 2012.05.25 |
[오류] PLS-00215: String length constraints must be in range (1 .. 32767) (0) | 2012.05.09 |
오라클 인덱스 생성 및 테이블스페이스변경 (0) | 2012.05.09 |