一个时间段,假如选择的是2011-09-10到2011-10-01这个时间段,我要查询这个时间段内所有白天的数据也就是小时是在06-18的所有数据。取小时的格式是这个样子的。to_date(recordtime, 'yyyy/MM/dd hh24:mi:ss'), 'hh24')//recordtime是时间列。是varchar2的类型

解决方案 »

  1.   

    select * from tb where substr(recordtime,11,2) between '06' and '18' 
    and to_date(recordtime,'YYYY-MM-DD') between to_date('2011-09-10','YYYY-MM-DD') and to_date('2011-10-01','YYYY-MM-DD')
      

  2.   


    select * from tb where substr(recordtime,12,2) between '06' and '18'  
    and to_date(recordtime,'YYYY-MM-DD') between to_date('2011-09-10','YYYY-MM-DD') and to_date('2011-10-01','YYYY-MM-DD')