How to iterate over a date range in PL/SQL

前端 未结 7 1931
梦毁少年i
梦毁少年i 2020-12-29 12:56

I need to write a report that generates summary totals against a table with date ranges for each record.

table data:
option   start_date   end_date
opt1              


        
7条回答
  •  难免孤独
    2020-12-29 13:23

    Just as an addition to the other techniques, one way I iterate over dates is the following:

    /* List of days for the past year, starting with today at midnight */
    SELECT TRUNC(SYSDATE) + 1 - LEVEL AS today,
           TRUNC(SYSDATE) + 2 - LEVEL AS tomorrow
    FROM DUAL
    CONNECT BY LEVEL <= 365
    

提交回复
热议问题