我有一个 SQL 查询,它接受一个日期参数(如果我要将它放入一个函数中),我需要在去年的每一天运行它.
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.
如何生成过去 365 天的列表,以便我可以使用直接 SQL 来执行此操作?
How to generate a list of the last 365 days, so I can use straight-up SQL to do this?
显然生成一个列表 0..364 也可以,因为我总是可以:
Obviously generating a list 0..364 would work, too, since I could always:
SELECT SYSDATE - val FROM (...);
无需使用超大表或 ALL_OBJECTS 表:
There's no need to use extra large tables or ALL_OBJECTS table:
SELECT TRUNC (SYSDATE - ROWNUM) dt
FROM DUAL CONNECT BY ROWNUM < 366
会解决问题.
这篇关于使用 SQL 生成日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!