2012-09-11 13 views
9

A continuación se muestra la consulta que estoy ejecutando para obtener actualizaciones en la última hora.Oracle obtiene registros actualizados en la última hora

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')); 

Nuestra base de datos es Oracle y que está fallando con

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. 

¿Cuál es la razón de este fracaso?

Respuesta

26

simplemente Reste 1/24 de sysdate para obtener el tiempo de hace 1 día

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