全,
我有一个sql,如下所示,它用于informatica查找sql。
当时间是凌晨2时至0时,select * from table where load_dt = trunc(sysdate)
当时间介于nextday 00.30到凌晨2时之间时,相同的sql应读为
select * from table where load_dt = trunc(sysdate-1)如何使这两个sql在单个sql中生成?
有可能吗?
谢谢
发布于 2016-03-01 20:57:52
我不确定我是否完全理解这个问题,但我假设,如果时间小于2时,您想从sysdate中减去1,否则保持当前sysdate。
你说过,凌晨2点到凌晨0点,早上0点半到凌晨2点…但我把它解释成了上面。
Select *
from table
where load_Dt = trunc(sysdate - case
when TO_CHAR(SYSTIMESTAMP,'HH24') < 2 then 1 else 0 end)或
Select *
from table
where load_Dt = trunc(sysdate - case
when EXTRACT(HOUR FROM SYSTIMESTAMP) < 2 then 1 else 0 end取决于是否需要时区偏移。
发布于 2016-03-01 21:01:55
在截断日期之前,您可以减去两个小时:
select *
from table
where load_dt = trunc(sysdate - 2/24.0) ;甲骨文也支持- interval '2' hour,但我有时很老套。
https://stackoverflow.com/questions/35733139
复制相似问题