我正在尝试通过将查询限制在相关时间戳之前和之后30分钟来加速时间戳比较查询。这是我正在使用的格式:
Ninject Module
我要做的是写一个条件,我将告诉系统只查找系统中未来的Causedat日期+ -00:30:00.000000000(30分钟)内的日期或过去那段时间。
我已经看到,例如,Causedat
-----
11-NOV-15 10.20.58.000000000 AM
11-NOV-15 10.19.41.877000000 AM
10-NOV-15 11.01.40.000000000 AM
10-NOV-15 11.00.50.460000000 AM
05-NOV-15 01.53.30.966000000 PM
05-NOV-15 01.47.31.000000000 PM
是合法的计算。是否可以像这样做类似的事情:
SYSDATE - SYSTIMESTAMP
请假设我正在搜索的日期和Causedat与此问题的格式相同(时间戳)。
感谢您为我提供的任何亮点。
答案 0 :(得分:1)
使用所需的间隔值对日期时间列进行直接算术。
WHERE search.date
BETWEEN Causedat - INTERVAL '30' MINUTE
AND Causedat + INTERVAL '30' MINUTE
答案 1 :(得分:1)
您可以在时间戳中添加间隔; you can read about datetime and interval arithmetic。存在从变量到间隔的转换函数,但是使用已知的固定值,您可以在此处使用an interval literal。您可以使用您拥有的完整字符串:
where search_date >= causedat - interval '000000000 00:30:00.000000000' day to second
and search_date <= causedat + interval '000000000 00:30:00.000000000' day to second;
或者只是非零部分:
where search_date >= causedat - interval '30' minute
and search_date <= causedat + interval '30' minute;
这些评估的简单演示:
select systimestamp,
systimestamp - interval '000000000 00:30:00.000000000' day to second as minus_30,
systimestamp + interval '000000000 00:30:00.000000000' day to second as plus_30
from dual;
SYSTIMESTAMP MINUS_30 PLUS_30
----------------------------------- ----------------------------------- -----------------------------------
18-NOV-15 11.39.09.597473000 +00:00 18-NOV-15 11.09.09.597473000 +00:00 18-NOV-15 12.09.09.597473000 +00:00
select systimestamp,
systimestamp - interval '30' minute as minus_30,
systimestamp + interval '30' minute as plus_30
from dual;
SYSTIMESTAMP MINUS_30 PLUS_30
----------------------------------- ----------------------------------- -----------------------------------
18-NOV-15 11.39.09.653809000 +00:00 18-NOV-15 11.09.09.653809000 +00:00 18-NOV-15 12.09.09.653809000 +00:00
答案 2 :(得分:0)
我刚刚完成了这个问题。我提供了一个简单的例子来说明我们如何实现这一目标。
SELECT A.DT
FROM
( SELECT SYSTIMESTAMP - INTERVAL '60' MINUTE AS DT FROM DUAL
UNION
SELECT SYSTIMESTAMP - INTERVAL '30' MINUTE AS DT FROM DUAL
UNION
SELECT SYSTIMESTAMP AS DT FROM DUAL
UNION
SELECT SYSTIMESTAMP + INTERVAL '30' MINUTE AS DT FROM DUAL
UNION
SELECT SYSTIMESTAMP + INTERVAL '60' MINUTE AS DT FROM DUAL
)A
WHERE A.DT BETWEEN (SYSTIMESTAMP - INTERVAL '30' MINUTE) AND (SYSTIMESTAMP + INTERVAL '30' MINUTE);
如果有帮助,请告诉我。