【问题标题】:Oracle get records updated in last one hourOracle 获取最近一小时内更新的记录
【发布时间】:2012-09-04 02:31:43
【问题描述】:

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

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.

这次失败的原因是什么?

【问题讨论】:

    标签: sql oracle date-arithmetic


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-07-07
      • 2017-03-28
      • 2018-08-02
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多