Oracle在最近一小时内更新了记录

时间:2012-09-11 07:42:20

标签: sql oracle date-arithmetic

以下是我在过去一小时内获取更新的查询。

select count(*) 
from my_table 
where last_updated_date between to_date(to_char(sysdate,'YYYY-MM-DD HH24'))-1/24 and to_date(to_char(sysdate,'YYYY-MM-DD HH24'));

我们的数据库是oracle,它失败了

ORA-01861: literal does not match format string
01861. 00000 -  "literal does not match format string"
*Cause:    Literals in the input must be the same length as literals in
           the format string (with the exception of leading whitespace).  If the
           "FX" modifier has been toggled on, the literal must match exactly,
           with no extra whitespace.
*Action:   Correct the format string to match the literal.

这次失败的原因是什么?

1 个答案:

答案 0 :(得分:33)

从sysdate中减去1/24以获得1小时前的时间

select count(*) from my_table where last_updated_date >= (sysdate-1/24)