--가상 테이블
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(COL ,',', KING_NM) ORDER BY ST).EXTRACT('//text()'
).GETSTRINGVAL()
, 2) KING_NM
FROM TEST_TABLE
GROUP BY COUNTRY
;
'DataBase > Sql' 카테고리의 다른 글
[ Oracle ] 테이블, 컬럼, 인덱스 목록 조회 (0) | 2018.11.05 |
---|---|
[Sql] 여러건의 특정 컬럼 행으로 표시하기. (0) | 2014.10.23 |
[Oracle] BLOB select (0) | 2014.01.16 |
[Sql] Oracle 까먹기쉬운 함수 정리 (0) | 2013.11.25 |
[Sql] Oracle - 계층구조 쿼리 (0) | 2013.11.25 |