oracle用指定的时间做查询条件怎么查不出数据。
如:sleect *from a where a.b=to_date('2009-02-28','yyyy-mm-dd')数据库里有数据就是不出来!

解决方案 »

  1.   

    应该这样:sleect *from a where to_date(a.b,'yyyy-mm-dd')='2009-02-28';
      

  2.   

    不是,应该用to_char()sleect *from a where to_char(a.b,'yyyy-mm-dd')='2009-02-28';
      

  3.   


    也可以用TRUNC把时间去掉,但是这样就用不了a.b上的索引了。但是可以建一个基于函数的索引来解决这个问题。sleect *from a where TRUNC(a.b)=to_date('2009-02-28','yyyy-mm-dd')
      

  4.   

    sleect *from a where to_char(a.b,'yyyy-MM-dd')='2009-02-28'
    是这样吧。M是要大写的吧。
      

  5.   

    看一下你数据库里是什么值不就知道了,带时间的话肯定查不到啊
    sleect *from a where a.b=to_date('2009-02-28','yyyy-mm-dd hh24:mi:ss')
      

  6.   

    select * 
    from a 
    where b >= to_date('20090228', 'yyyymmdd')
      and b < to_date('20090228', 'yyyymmdd') + 1这样不需要额外增加索引,也可以使用b的索引,只是多写一句而已。
      

  7.   

    这要根据你数据库的日期是字符格式还是日期格式的
    把日期转换成字符格式:   sleect *from a where to_char(a.b,'yyyy-mm-dd')='2009-02-28'  把字符格式转换成日期格式: sleect * from a where to_date(a.b,'yyyymmdd') =to_date(20090228,'yyyymmdd)而且 函授里面的 'yyyy-mm-dd' 格式不区分大小写
      

  8.   

    select * 
    from a 
    where b >= to_date('20090228', 'yyyymmdd') 
      and b < to_date('20090228', 'yyyymmdd') + 1