一个表中的date型字段中存储的数据有类似2012-8-28 6:52:44这样包含时间的,也有2012-8-28这样不包含时间的。
在按日期范围查询当日数据时,用 dt BETWEEN to_date('2012-8-28 00:00:01','yyyy-mm-dd hh24:mi:ss') and to_date('2012-8-28 23:59:59','yyyy-mm-dd hh24:mi:ss')这样的方式查不到日期数据不包含时间的类似2012-8-28这样的数据,怎么办呢?求教,谢谢

解决方案 »

  1.   

    BETWEEN to_date('2012-8-28 00:00:00','yyyy-mm-dd hh24:mi:ss') 
    and to_date('2012-8-28 23:59:59','yyyy-mm-dd hh24:mi:ss')
    '2012-8-28 00:00:01'==>'2012-8-28 00:00:00'
      

  2.   

    select * from dual where trunc(to_date(dt,'yyyy-mm-dd hh24:mi:ss'),'dd')
     BETWEEN to_date('2012-8-28','yyyy-mm-dd') and to_date('2012-8-29','yyyy-mm-dd');
      

  3.   

    2012-8-28 = 2012-8-28 00:00:00
    所以只要改成
    dt BETWEEN to_date('2012-8-28 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-8-28 23:59:59','yyyy-mm-dd hh24:mi:ss')
    即可
      

  4.   


    select * from 你的表 where to_char(dt,'yyyy-mm-dd')='2012-08-28';