如何从 SYSDATE 获取前几天、几个月、季节

How to get previous Days, Months, Season from SYSDATE

我是 Oracle/Toad 的新人。 我正在尝试从 SYSDATE 中获取以前的天数、月数和季节,就像这样:

20190102
20190101
20181231
20181230
20181201
20181101
20181001
20180701
20180401
20180101
20171001
20170701 

有人可以帮我解决这个问题吗?

SELECT to_date(to_char(sysdate,'yyyymmdd'),'yyyymmdd'),
       to_date(to_char(sysdate,'yyyymmdd')-1,'yyyymmdd'), 
       to_date(to_char(sysdate,'yyyymmdd')-2,'yyyymmdd'), 
       to_date(to_char(sysdate,'yyyymmdd')-3,'yyyymmdd'),
       trunc(sysdate)-(to_number(to_char(sysdate,'dd'))-1)
       from dual;

我卡在了这一点上。

I'm trying to get previous Days, Month, Seasons from SYSDATE

您的预期日期系列的逻辑不清楚,但是根据引用,这里是实现您的目标的基本工具:

SELECT 
    trunc(sysdate) - 1 last_day,
    add_months(trunc(sysdate, 'MM'), -1) first_day_of_last_month,
    add_months(trunc(sysdate, 'Q'), -3) first_day_of_last_quarter
FROM DUAL

产量:

  LAST_DAY  | FIRST_DAY_OF_LAST_MONTH | FIRST_DAY_OF_LAST_QUARTER
  :-------- | :---------------------- | :------------------------
  06-JAN-19 | 01-DEC-18               | 01-OCT-18                

db<>fiddle here