How to generate list of all dates between sysdate-30 and sysdate+30?

大憨熊 提交于 2019-12-01 19:20:19
select trunc(sysdate)+31-level from dual connect by level <=61

This is a good method for generating any arbitrary list of values.

Or another method: pick a table with a lot of rows

select sysdate+30 - rownum from user_objects where rownum<61
SeanKilleen

In order to meet my requirements of being sysdate -30 and sysdate + 30 in a range, this seems be the most elegant way of doing things for now:

SELECT *
FROM   (SELECT TRUNC(SYSDATE - ROWNUM) DT
        FROM   DUAL
        CONNECT BY ROWNUM < 31
        UNION
        SELECT TRUNC(SYSDATE + ROWNUM) DT
        FROM   DUAL
        CONNECT BY ROWNUM < 31)DATERANGE; 

I used this answer from this SO Question and expanded upon that thinking, using a union to join the queries that went in separate directions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!