代码:
--oracle 求两个日期之间的所有日期
SELECT TO_CHAR((TO_DATE(KSRQ, 'yyyy-MM-dd') + (ROWNUM - 1)), 'yyyy-MM-dd') DT
FROM DUAL
CONNECT BY ROWNUM <=
(TO_DATE(JSRQ, 'yyyy-MM-dd') - TO_DATE(KSRQ, 'yyyy-MM-dd') + 1)
实例:
字符串格式的日期:
SELECT TO_CHAR((TO_DATE('2020-12-01', 'yyyy-MM-dd') + (ROWNUM - 1)), 'yyyy-MM-dd') DT
FROM DUAL
CONNECT BY ROWNUM <=
(TO_DATE('2020-12-23', 'yyyy-MM-dd') - TO_DATE('2020-12-01', 'yyyy-MM-dd') + 1)
日期格式的日期:
SELECT (TO_DATE('2020-12-01', 'yyyy-MM-dd') + (ROWNUM - 1)) DT
FROM DUAL
CONNECT BY ROWNUM <=
(TO_DATE('2020-12-23', 'yyyy-MM-dd') - TO_DATE('2020-12-01', 'yyyy-MM-dd') + 1)