(1)不含开始日期,含结束日期
SELECT to_char(add_months(to_date(SUBSTR('2016-11-01',0,7),'yyyy-mm'),ROWNUM),'YYYY-MM')AS vc_month
FROM all_objects WHERE ROWNUM <=
(SELECT months_between(to_date(SUBSTR('2017-11-31','YYYY-MM'),to_date(SUBSTR('2016-11-01','YYYY-MM'))FROM dual);
(2)含开始日期,不含结束日期
SELECT to_char(add_months(to_date(SUBSTR('2016-11-01',ROWNUM-1),'YYYY-MM')AS vc_month
FROM all_objectsWHERE ROWNUM <=
(SELECT months_between(to_date(SUBSTR('2017-11-31','YYYY-MM'))FROM dual)
SELECT to_char(add_months(to_date(SUBSTR('2016-11-01','YYYY-MM'))+1FROM dual)
结果
(4)不含开始日期,结束日期多一个月
SELECT to_char(add_months(to_date(SUBSTR('2016-11-01',ROWNUM),'YYYY-MM')AS vc_month
FROM all_objectsWHERE ROWNUM <=
(SELECT months_between(to_date(SUBSTR('2017-11-31',to_date(SUBSTR('2016-11-01','YYYY-MM'))+1FROM dual)
结果原文链接:https://www.f2er.com/oracle/206913.html