我总是需要明年 1 号在我的 Oracle SQL Developer 中进行查询。因此,从今天的角度来看,日期格式应如下所示:
01-JAN-24
但是,一旦我们算到 2024 年,今年应该会自动调整。
我该怎么做?
一种选择是将
sysdate
截断为 year(并获取今年 1 月 1 日),然后添加 12 个月:
SQL> select add_months(trunc(sysdate, 'yyyy'), 12) result from dual;
RESULT
-------------------
01.01.2024 00:00:00
SQL>
我认为
trunc(date)
是您需要的功能:
select
trunc(sysdate, 'y') current_year
from
dual t1
这将返回当年的 1 月 1 日。
select
add_months(trunc(sysdate, 'y'), 12) shifted_year
from
dual t1
现在我们只需添加 12 个月