select * from tablename where to_char(columns,'yyyy-mm-dd') > '2003-12-01' and to_char(columns,'yyyy-mm-dd') < '2003-12-31';

解决方案 »

  1.   

    select * from tablename where trandate between to_date('20030101','yyyymmdd') 
    and to_date('20031231 23:59:59');或者
    select * from tablename where to_char(trandate,'yyyy')= 2003
      

  2.   

    这样应该可以快一点select * from tablename where columns > to_date('2003-12-01','yyyy-mm-dd') and to_charcolumns < to_date('2003-12-31','yyyy-mm-dd');
      

  3.   

    这样应该可以快一点select * from tablename where columns > to_date('2003-12-01','yyyy-mm-dd') and to_charcolumns < to_date('2003-12-31','yyyy-mm-dd');
      

  4.   

    select * from tablename where to_char(col,'yyyymm')= '200312'
      

  5.   

    select * from tablename where to_char(日期字段,'YYYY-MM') = '2003-12' 如果要查一年的数据
    select * from tablename where to_char(日期字段,'YYYY') = '2003'
      

  6.   

    看到这么多的写法,不错不错!
    速度排序:(由快到慢)
    1:select * from tablename where columns > to_date('2003-12-01','yyyy-mm-dd') and columns < to_date('2003-12-31','yyyy-mm-dd');2:select * from tablename where to_char(columns,'YYYY') = '2003'3:select * from tablename where to_char(columns,'yyyy-mm-dd') > '2003-12-01' and to_char(columns,'yyyy-mm-dd') < '2003-12-31';
      

  7.   

    尽量不要在条件左边使用函数,可能导致不能使用index而影响性能
      

  8.   

    可以查看FAQ裡的日期和時間函數大全
    介紹的比較的詳細
      

  9.   

    select * from tablename 
    where columns > to_date('2003-12-01','yyyy-mm-dd') 
    and columns < to_date('2003-12-31','yyyy-mm-dd');
    不错
      

  10.   

    呵呵 如果一定要用to_char(columns,'yyyy-mm-dd')  那最好建个函数索引