我从数据库查询数据 
select * from a where ... 
and operate_date >= to_date('2008-12-08', 'yyyy-mm-dd') 
and operate_date <= to_date('2008-12-15', 'yyyy-mm-dd') 
operate_date是Date类型的,但是现在有一个问题,就是operate_date查出的出具都带有时间,例如2008-12-15 10:26:41 
这样的话,我想查15日的就查不出来了,因为15日相当于2008-12-15 00:00:00,是最小的 
我试着想把SQL语句改成 
and to_date(operate_date,'yyyy-mm-dd') >= to_date('2008-12-08', 'yyyy-mm-dd') 
and to_date(operate_date,'yyyy-mm-dd') <= to_date('2008-12-15', 'yyyy-mm-dd') 
但是报错,ora-01861 文字与格式字符串不匹配 
该怎么办啊??

解决方案 »

  1.   

    select * from a where ... 
    and to_char(operate_date, 'yyyy-mm-dd') >= '2008-12-08'
    and to_char(operate_date, 'yyyy-mm-dd') <= '2008-12-15'
      

  2.   

    真的可以哦,非常感谢
    不过我不明白,to_char(operate_date, 'yyyy-mm-dd') 之后就转为字符串了,字符串也能比较大小吗?
      

  3.   

    truncate(operate_date)>=to_date('2008-12-08', 'yyyy-mm-dd')
      

  4.   

    select * from a where ... 
    and to_char(operate_date,'yyyy-mm-dd')>= '2008-12-08'
    and to_char(operate_date,'yyyy-mm-dd')<= '2008-12-15' 
      

  5.   

    如果有索引问题,推荐用:
    and operate_date >= to_date('2008-12-08', 'yyyy-mm-dd') 
    and operate_date < to_date('2008-12-15', 'yyyy-mm-dd')+1