数据:  时间段                         学员名称
     2010-05-03 12:21:11                张三
     2010-05-03 14:21:11                李四
     2010-05-03 09:21:11                王五
问题:开始时间:2010-05-03 09
     结束时间:2010-05-03 12
     之间的数据,请高手帮帮忙

解决方案 »

  1.   

    oracle 日期范围查询问题 
    select * from aaa where to_char(rq,'yyyymmdd') between '20011101' and '20020301';
    直接在rq上加函数,如果应用大(这个表内数据很多时),查询速度会相当慢的,为了提高查询速度,强烈建议这样书写:
    select * from aaa where rq between to_date('2001-11-01','yyyy-MM-DD') and to_date('2002-03-01' ,'YYYY-MM-DD');
    推荐使用
    select * from aaa where rq>;=to_date('2001-11-01','yyyy-MM-DD') and rq<=to_date('2002-03-01' ,'YYYY-MM-DD');用between的函数可能会慢些
      

  2.   

    select *
    from table1
    where 时间段 between to_date('2010-05-03 09','yyyy-mm-dd hh24') and to_date('2010-05-03 12','yyyy-mm-dd hh24');
      

  3.   


    select 时间段,学员名称
    from tb
    where to_char(时间段,'yyyy-mm-dd hh24:mi:ss') between '2010-05-03 09:00:00' and '2010-05-03 12:00:00'
      

  4.   

    select * from 表名 where rq>=to_date('2001-05-03 9:00:00','yyyy-MM-DD h24:mi:ss') and rq<=to_date('2010-05-03 12:00:00' ,'YYYY-MM-DD h24:mi:ss');
      

  5.   

    我知道都是to_date 但是查询出来的数据不准确
      

  6.   


    create table ss_csdn(
        dateTime date,
        stuName varchar2(20)
    )select * from ss_csdn
    insert into ss_csdn values (to_date('2010-05-03 12:21:11','yyyy-mm-dd hh24:mi:ss'),'张三');
    insert into ss_csdn values (to_date('2010-05-03 14:21:11','yyyy-mm-dd hh24:mi:ss'),'李四');
    insert into ss_csdn values (to_date('2010-05-03 11:21:11','yyyy-mm-dd hh24:mi:ss'),'王八');
    insert into ss_csdn values (to_date('2010-05-03 09:21:11','yyyy-mm-dd hh24:mi:ss'),'王五');
    select * from ss_csdn where datetime between to_date('2010-05-03 09:21:11','yyyy-mm-dd hh24:mi:ss')
           and to_date('2010-05-03 12:21:11','yyyy-mm-dd hh24:mi:ss');