20

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

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.

这次失败的原因是什么?

4

1 回答 1

51

只需从 sysdate 中减去 1/24 即可得到 1 小时前的时间

select count(*) from my_table where last_updated_date >= (sysdate-1/24)
于 2012-09-11T07:45:12.227 回答