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
这样应该可以快一点select * from tablename where columns > to_date('2003-12-01','yyyy-mm-dd') and to_charcolumns < to_date('2003-12-31','yyyy-mm-dd');
这样应该可以快一点select * from tablename where columns > to_date('2003-12-01','yyyy-mm-dd') and to_charcolumns < to_date('2003-12-31','yyyy-mm-dd');
select * from tablename where to_char(col,'yyyymm')= '200312'
select * from tablename where to_char(日期字段,'YYYY-MM') = '2003-12' 如果要查一年的数据 select * from tablename where to_char(日期字段,'YYYY') = '2003'
看到这么多的写法,不错不错! 速度排序:(由快到慢) 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';
尽量不要在条件左边使用函数,可能导致不能使用index而影响性能
可以查看FAQ裡的日期和時間函數大全 介紹的比較的詳細
select * from tablename where columns > to_date('2003-12-01','yyyy-mm-dd') and columns < to_date('2003-12-31','yyyy-mm-dd'); 不错
and to_date('20031231 23:59:59');或者
select * from tablename where to_char(trandate,'yyyy')= 2003
select * from tablename where to_char(日期字段,'YYYY') = '2003'
速度排序:(由快到慢)
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';
介紹的比較的詳細
where columns > to_date('2003-12-01','yyyy-mm-dd')
and columns < to_date('2003-12-31','yyyy-mm-dd');
不错