Generate a range of dates using SQL

前端 未结 15 1352
面向向阳花
面向向阳花 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:59

    A method quite frequently used in Oracle is something like this:

    select trunc(sysdate)-rn
    from
    (   select rownum rn
        from   dual
        connect by level <= 365)
    /
    

    Personally, if an application has a need for a list of dates then I'd just create a table with them, or create a table with a series of integers up to something ridiculous like one million that can be used for this sort of thing.

提交回复
热议问题