첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
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
    COUNTRY
   ,SUBSTR(XMLAGG(XMLELEMENT('nm', ',', KING_NM) ORDER BY ST).EXTRACT('//text()').GETSTRINGVAL(), 2) KING_NM
FROM TEST_TABLE
GROUP BY COUNTRY;

/*
COUNTRY KING_NM
------- ---------------------------
고구려  동명성왕,유리왕,대무신왕
백제    온조왕,다루왕,기루왕
신라    박혁거세,남해왕,유리이사금
*/
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요