,就是record表里有recordfile这个字段,他的记录是0\102\yymmddhhmmss.wav模式,我想取yymmddhhmmss在现在到一小时之前的记录,sql语句怎么写?

解决方案 »

  1.   

    select * from record where to_date(substr(recordfile,7,12),'yyMMddhhmiss') between sysdate- interval '1' hour and sysdate;
      

  2.   

    不对吧....ORACLE的年份必须是4位数的
      

  3.   

    SQL> select * from test5;A
    --------------------------------------------------------------------------------0\102\050810111111.wav
    0\102\050810111111.wav
    0\102\050810111121.wav
    0\102\050812111121.wav
    0\102\050811111121.wavSQL> select * from test5 where to_date(substr(a,7,12),'yyMMddhhmiss')
      2  between sysdate- interval '1' hour and sysdate;A
    --------------------------------------------------------------------------------0\102\050811111121.wavSQL>
      

  4.   

    楼上的方法基本可行,不过我想目录结构应该是不确定的,有可能是这样的:
    0\11\102\050811111121.wav,而yymmddhhmmss是确定的,所以下面的方法会更准确些:
    把楼上兄弟的sql中substr(recordfile,7,12)替换为
    substr(recordfile,instr(recordfile,'\',-1,1)+1,12)  
    //instr()函数这里从后往前检索第1次出现'\'的位置,从前面检索有可能不对,因为目录深度不确定
      

  5.   

    嗯,或者
    where to_date(substr(recordfile,-16,12),'yymmddhh24miss') between trunc(sysdate,'hh24') and sysdate;
      

  6.   

    sorry!where to_date(substr(recordfile,-16,12),'yymmddhh24miss') 
    between sysdate-1/24 and sysdate;
      

  7.   

    select * from record where to_date(substr(recordfile,instr(recordfile,'.')-12,12),'yyMMddhhmiss') between sysdate- interval '1' hour and sysdate;
      

  8.   

    有意思,不过写文件名到DB的时候,把时间写进去了会怎么样任何时候sql复杂到自己没辙,是不是应该先考察需求、在优化数据模型我承认有些业务sql不得不如此,问题是上述的评估工作到底做没做