다수의 컬럼에 콤마를 구분자로 코드값들이 들어 있습니다.
각각의 값들을 분리해서 새로운 ROW 데이터를 만들려고 합니다.
예를들면
WITH T(ALCD, CAPA, INJI, RESN) AS
( SELECT 'RR01', '3300,3800', 'GDI', 'KOR' FROM DUAL
UNION ALL SELECT 'RR02', '2000,2400', 'MPI,GDI', 'KOR,EUR' FROM DUAL
UNION ALL SELECT 'RR03', '1000', '', 'KOR' FROM DUAL
)
예상결과 ==>
ALCD CAPA INJI RESN
---- ---- ---- ----
RR01 3300 GDI KOR
RR01 3800 GDI KOR
RR02 2000 MIP KOR
RR02 2000 MIP EUR
RR02 2000 GDI KOR
RR02 2000 GDI EUR
RR02 2400 MIP KOR
RR02 2400 MIP EUR
RR02 2400 GDI KOR
RR02 2400 GDI EUR
RR03 1000 KOR
--------------------
실제 데이터가 1000건 정도 됩니다.
이걸 위와같이 나열하면 몇건 나올지 ㅎㄷㄷ..
고수분들의 도움 바랍니다.
항상 감사합니다.
-- 답만 맞추는 아찌 ㅜㅜ 정렬은 못했어요 WITH T(ALCD, CAPA, INJI, RESN) AS ( SELECT 'RR01', '3300,3800', 'GDI', 'KOR' FROM DUAL UNION ALL SELECT 'RR02', '2000,2400', 'MPI,GDI', 'KOR,EUR' FROM DUAL UNION ALL SELECT 'RR03', '1000', '', 'KOR' FROM DUAL ) SELECT ALCD ,DECODE(CAPA,'@','',CAPA) CAPA ,DECODE(INJI,'@','',INJI) INJI ,DECODE(RESN,'@','',RESN) RESN FROM (SELECT T.ALCD , A.CAPA , B.INJI , C.RESN FROM T , (SELECT ALCD ,REGEXP_SUBSTR(NVL(CAPA,'@'), '[^,]+', 1, lv ) CAPA FROM T , (SELECT LEVEL lv FROM DUAL CONNECT BY LEVEL <= 100 )) A , (SELECT ALCD ,REGEXP_SUBSTR(NVL(INJI,'@'), '[^,]+', 1, lv ) INJI FROM T , (SELECT LEVEL lv FROM DUAL CONNECT BY LEVEL <= 100 )) B , (SELECT ALCD ,REGEXP_SUBSTR(NVL(RESN,'@'), '[^,]+', 1, lv ) RESN FROM T , (SELECT LEVEL lv FROM DUAL CONNECT BY LEVEL <= 100 )) C WHERE T.ALCD = A.ALCD(+) AND T.ALCD = B.ALCD(+) AND T.ALCD = C.ALCD(+) ) WHERE CAPA IS NOT NULL AND INJI IS NOT NULL AND RESN IS NOT NULL
WITH T(ALCD, CAPA, INJI, RESN) AS ( SELECT 'RR01', '3300,3800', 'GDI', 'KOR' FROM DUAL UNION ALL SELECT 'RR02', '2000,2400', 'MPI,GDI', 'KOR,EUR' FROM DUAL UNION ALL SELECT 'RR03', '1000', '', 'KOR' FROM DUAL ) select alcd , capa, inji , resn from ( select alcd , regexp_substr( capa, '[^,]+' , 1, 1) as capa1 , regexp_substr( capa, '[^,]+' , 1, 2) as capa2 , nvl(regexp_substr( inji, '[^,]+' , 1, 1),' ') as inji1 , regexp_substr( inji, '[^,]+' , 1, 2) as inji2 , regexp_substr( resn, '[^,]+' , 1, 1) as resn1 , regexp_substr( resn, '[^,]+' , 1, 2) as resn2 from t ) unpivot ( capa for a in ( capa1 , capa2 ) ) unpivot ( inji for b in ( inji1 , inji2 ) ) unpivot ( resn for c in ( resn1 , resn2 ) )