SELECT listagg(YYYYMM,',') within group (order by YYYYMM) DATE_STR from ( SELECT DISTINCT(TO_CHAR(T.ROWDATE, 'yyyy-mm')) YYYYMM FROM ( SELECT ROWNUM, TO_DATE('2018-01', 'yyyy-mm') + ROWNUM - 1 ROWDATE FROM DUAL CONNECT BY ROWNUM < TO_DATE('2018-07', 'yyyy-mm') - TO_DATE('2018-01', 'yyyy-mm') + 2) T ORDER BY YYYYMM )