oracle中获取年份、月份段内的时间
程序员文章站
2022-06-07 12:30:50
...
获取日期列表:
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
转载于:https://blog.51cto.com/10928079/1718686