转自 : http://blog.csdn.net/jumtre/article/details/46345733
获取日期列表:
- SELECT TO_CHAR(TO_DATE('2014-10-01', 'yyyy-MM-dd') + ROWNUM - 1, 'yyyyMMdd') as daylist
- FROM DUAL
- CONNECT BY ROWNUM <=
- trunc(to_date('2015-06-01', 'yyyy-MM-dd') -
- to_date('2014-10-01', 'yyyy-MM-dd')) + 1
获取月份列表:
- SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2014-10', 'yyyy-MM'), ROWNUM - 1),
- 'yyyyMM') as monthlist
- FROM DUAL
- CONNECT BY ROWNUM <=
- months_between(to_date('2015-06', 'yyyy-MM'),
- to_date('2014-10', 'yyyy-MM')) + 1
获取年份列表:
- SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2014-10', 'yyyy-MM'), (ROWNUM - 1) * 12),
- 'yyyy') as yearlist
- FROM DUAL
- CONNECT BY ROWNUM <=
- months_between(to_date('2015-06', 'yyyy-MM'),
- to_date('2014-10', 'yyyy-MM')) / 12 + 1