with t_name as ( select 'sch1' as col1, '20240906' as col2, 5 as col3 from dual union all select 'sch2' as col1, '20241001' as col2, 3 as col3 from dual ) select t1.col1 , to_char(to_date(col2,'yyyymmdd') + ((level -1) * 7),'yyyymmdd') as dt from t_name t1 connect by level <= col3 and prior col1 = col1 and prior sys_guid() is not null order by 1, 2
음... 원래 conect by level 은 단일행 데이터에 적용하는거라고 알고있는데...
아래 and 부분을 이용하면 여러행이 있는 데이터도 정상적으로 출력이 되네요.
단지 데이터량이 많아질때 어떤 성능적 이슈가 있을지는 잘 모르겠습니다... 만
일단은 원하시는 데이터가 나오기는 할꺼 같네요.
WITH SCHEDULES AS ( SELECT 'SCH1' AS SCHEDULE_NAME, TO_DATE('20240906', 'YYYYMMDD') AS START_DT, 5 AS REPEAT_CNT FROM DUAL UNION ALL SELECT 'SCH2' AS SCHEDULE_NAME, TO_DATE('20241001', 'YYYYMMDD') AS START_DT, 3 AS REPEAT_CNT FROM DUAL ), NUMBERS AS ( SELECT LEVEL AS N FROM DUAL CONNECT BY LEVEL <= (SELECT MAX(REPEAT_CNT) FROM SCHEDULES) ) SELECT S.SCHEDULE_NAME AS SCHEDULE_NAME , TO_CHAR(S.START_DT + (N.N - 1) * 7, 'YYYYMMDD') AS REPEATED_DT FROM SCHEDULES S , NUMBERS N WHERE N.N <= S.REPEAT_CNT ORDER BY S.SCHEDULE_NAME , REPEATED_DT