oracle查询当前时间点最近的数据例如:2011-02-10 13:20:34  左右的数据

解决方案 »

  1.   

    我不知道 oracle 有没有在插入一条记录时  同时记录当前时间;
    但lz若在设计表结构时有个插入时间字段,那么这个问题应该不难解决
      

  2.   

    select sysdate from dual;查询当前时间
    select sysdate+1/48 from dual;查询后半个小时的时间
    select sysdate+1/24 from dual:查询后一个小时的时间你可以根据上述规律,做你想看到的时间
      

  3.   

    select * from tb as of timestamp sysdate-1;
      

  4.   

    create table tab_test(col1 varchar2,
                          ....
                          col10 date)
    -- 下面语句查出当前时间(sysdate)前后半小时内的数据。
    select * from tab_test
    where col10 >= sysdate - 1/48
      and col10 <= sysdate - 1/48
      

  5.   

    你要的是某个表在2011-02-10 13:20:34 时间表内的数据?
    还是某个表内时间字段在2011-02-10 13:20:34 附近的数据.
    如果是第一种 ,oracle 提高flash query.就是9楼那样.
    如果是第二种情况,就是查询表内的数据
      

  6.   

    是第二种情况,首先你的表结构中一定要有一个时间字段,该字段表示这条记录产生的时间.
    其次,你要查询某个时间点附近的数据,电脑并不理解"附近"的意义,因此你要明确"附近"指的是1分钟内还是5分钟内的数据(或者更长) .
    对于过去某个时间点,"附件" 有包含时间点前的数据和时间点后的数据.假设你要查询当前时间点30分钟内的数据.
    create table tab_test(col1 varchar2,
      ....
      col10 date)
    -- 下面语句查出当前时间(sysdate)前后半小时内的数据。
    select * from tab_test
    where col10 >= sysdate - 1/48
      and col10 <= sysdate
      

  7.   

    查询当前时间(sysdate)前后5分钟内的数据。
      

  8.   

    当前时间只有前,没有后. 只有过去时间点才有后.1表示一天,24小时,5分钟就是1/288
    select * from tab_test
    where col10 >= sysdate - 1/288
      and col10 <= sysdate