oracle擷取某時間段內的年份、月份、日期列表,oracle年份

來源:互聯網
上載者:User

oracle擷取某時間段內的年份、月份、日期列表,oracle年份

擷取日期列表:

SELECT TO_CHAR(TO_DATE('2014-10-01', 'yyyy-MM-dd') + ROWNUM - 1, 'yyyyMMdd') as daylist  FROM DUALCONNECT 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 DUALCONNECT 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 DUALCONNECT BY ROWNUM <=           months_between(to_date('2015-06', 'yyyy-MM'),                          to_date('2014-10', 'yyyy-MM')) / 12 + 1


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.