첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
WITH TEST_TABLE AS
(
    SELECT '고구려' COUNTRY, '1대' ST, '동명성왕'   KING_NM FROM DUAL UNION ALL
    SELECT '고구려' COUNTRY, '3대' ST, '대무신왕'   KING_NM FROM DUAL UNION ALL
    SELECT '백제'   COUNTRY, '1대' ST, '온조왕'     KING_NM FROM DUAL UNION ALL
    SELECT '고구려' COUNTRY, '2대' ST, '유리왕'     KING_NM FROM DUAL UNION ALL
    SELECT '백제'   COUNTRY, '3대' ST, '기루왕'     KING_NM FROM DUAL UNION ALL
    SELECT '신라'   COUNTRY, '2대' ST, '남해왕'     KING_NM FROM DUAL UNION ALL
    SELECT '신라'   COUNTRY, '1대' ST, '박혁거세'   KING_NM FROM DUAL UNION ALL
    SELECT '백제'   COUNTRY, '2대' ST, '다루왕'     KING_NM FROM DUAL UNION ALL
    SELECT '신라'   COUNTRY, '3대' ST, '유리이사금' KING_NM FROM DUAL
)
SELECT *
FROM   TEST_TABLE
WHERE  COUNTRY IN
(
    SELECT REGEXP_SUBSTR('백제/신라', '[^/]+', 1, LEVEL)
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('백제/신라', '/') + 1
)
ORDER BY COUNTRY, ST;

/*
COUNTRY ST  KING_NM
------- --- ----------
백제    1대 온조왕
백제    2대 다루왕
백제    3대 기루왕
신라    1대 박혁거세
신라    2대 남해왕
신라    3대 유리이사금
*/
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요