例子
我在查询的时候 填入的日期都是没有时间的 比如 2011-10-10
而数据库中时间是 2011-10-10 12:12:12
我在写sql语句的时候
select * from table where datetime <to_date(var,'yyyy-mm-dd')
不加时间的话就查不出来了 有没有可以不用比较时间的 函数呢只比较日期

解决方案 »

  1.   

    where trunc(datetime)<to_date(var,'yyyy-mm-dd')
      

  2.   

    select * from table 
    where trunc(datetime) <to_date(var,'yyyy-mm-dd')
      

  3.   


    -- 左边的函数是多余滴,只会让你的SQL“低效”运行!
      

  4.   

    -- 低效:
    select * from table 
    where trunc(datetime) <to_date(var,'yyyy-mm-dd')-- 高效:
    select * from table 
    where datetime <to_date(var,'yyyy-mm-dd')