Generate a range of dates using SQL

前端 未结 15 1333
面向向阳花
面向向阳花 2020-11-28 05:47

I have a SQL query that takes a date parameter (if I were to throw it into a function) and I need to run it on every day of the last year.

How to generate a list of

15条回答
  •  攒了一身酷
    2020-11-28 05:56

    I had the same requirement - I just use this. User enters the number of days by which he/she wants to limit the calendar range to.

      SELECT DAY, offset
        FROM (SELECT to_char(SYSDATE, 'DD-MON-YYYY') AS DAY, 0 AS offset
                FROM DUAL
              UNION ALL
              SELECT to_char(SYSDATE - rownum, 'DD-MON-YYYY'), rownum
                FROM all_objects d)
                where offset <= &No_of_days
    

    I use the above result set as driving view in LEFT OUTER JOIN with other views involving tables which have dates.

提交回复
热议问题