고수님들 도움 요청 합니다
select 'A' as PK
, 'AAAA' as CODE
, '테스트1' as CD_NM
from dual
union all
select 'A' as PK
, 'BBBB' as CODE
, '테스트2' as CD_NM
from dual
union all
select 'A' as PK
, 'CCCC' as CODE
, '테스트3' as CD_NM
from dual
>>> 결과
'AAAA','테스트1'>'BBBB', '테스트2'>'CCCC','테스트3'
-- 항목 구분자 ',' , 레코드별 구분자 '>'
이렇게 한줄로 나오는 쿼리 부탁드립니다
WITH t AS ( SELECT 'A' pk, 'AAAA' code, '테스트1' cd_nm FROM dual UNION ALL SELECT 'A', 'BBBB', '테스트2' FROM dual UNION ALL SELECT 'A', 'CCCC', '테스트3' FROM dual ) SELECT pk , LISTAGG(code ||','|| cd_nm, '>') WITHIN GROUP(ORDER BY code) x1 , LISTAGG(''''||code||''','''||cd_nm||'''', '>') WITHIN GROUP(ORDER BY code) x2 FROM t GROUP BY pk ;