2008-08-03 11:59:05    需求是查出它之前1小时的数据 oracle有什么函数可以用?
怎么用?比如字段   scan_date   答意就行谢谢!

解决方案 »

  1.   

    Datetime Functions 
    Datetime functions operate on date (DATE), timestamp (TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE), and interval (INTERVAL DAY TO SECOND, INTERVAL YEAR TO MONTH) values.Some of the datetime functions were designed for the Oracle DATE datatype (ADD_MONTHS, CURRENT_DATE, LAST_DAY, NEW_TIME, and NEXT_DAY). If you provide a timestamp value as their argument, then Oracle Database internally converts the input type to a DATE value and returns a DATE value. The exceptions are the MONTHS_BETWEEN function, which returns a number, and the ROUND and TRUNC functions, which do not accept timestamp or interval values at all.The remaining datetime functions were designed to accept any of the three types of data (date, timestamp, and interval) and to return a value of one of these types.All of the datetime functions that return current system datetime information, such as SYSDATE, SYSTIMESTAMP, CURRENT_TIMESTAMP, and so forth, are evaluated once for each SQL statement, regardless how many times they are referenced in that statement.The datetime functions are:
    ADD_MONTHS
    CURRENT_DATE
    CURRENT_TIMESTAMP
    DBTIMEZONE
    EXTRACT (datetime)
    FROM_TZ
    LAST_DAY
    LOCALTIMESTAMP
    MONTHS_BETWEEN
    NEW_TIME
    NEXT_DAY
    NUMTODSINTERVAL
    NUMTOYMINTERVAL
    ROUND (date)
    SESSIONTIMEZONE
    SYS_EXTRACT_UTC
    SYSDATE
    SYSTIMESTAMP
    TO_CHAR (datetime)
    TO_TIMESTAMP
    TO_TIMESTAMP_TZ
    TO_DSINTERVAL
    TO_YMINTERVAL
    TRUNC (date)
    TZ_OFFSET
      

  2.   

    select * from 表名 where scan_date <= sysdate - 1/24试试
      

  3.   

    //2008-08-03 11:59:05 
    // 查询系统时间前一个小时的时间
    SQL> select sysdate + interval '1' hour  from dual;SYSDATE+INTERVAL'1'HOUR
    -----------------------
    2009-4-15 17:33:10
     
    //查询字段(DATE类型)前一个小时的时间
     SQL>  select  t.opendate + interval '1' hour   from tbl_store t;T.OPENDATE+INTERVAL'1'HOUR
    --------------------------
    2009-3-29 19:58:59
    2009-3-29 20:03:44
      

  4.   

    说反了
    呵呵纠正
    + 和 - 啊
    LZ该知道
     select  t.opendate - interval '1' hour   from tbl_store t  select sysdate - interval '1' hour  from dual 
      

  5.   

    select * from 表名 where scan_date  <= sysdate - 1/24 
      

  6.   

    Oracle里日期可以直接相减
    或者用add_day函数
    for example
    select * from yourtable where scan_date <= add_day(yourdate, -1/24)