玖叶教程网

前端编程开发入门

oracle date类型数据 查询优化(oracle date查询条件)

数据量小,不存在太多优化的情况 ,因为区别太小,看不出来,当一张表上了百万以上时,区别比较明显,尤其是过千万和亿数据,就天壤之别了。


创建测试表

created table test(

id varchar2(20) not null,

dtime date

)

插入6000000数据

declare
i number;
k number;
begin
k:=0;
for i in 1 .. 6000000 loop
insert into test(id,dtime) values('1',sysdate-k);
if i/10000 =0 then
k:=k+1;
commit;
end if;
end loop;
commit;
end;

第一种查询语句

select * from test where to_char(dtime,'yyyy-MM-dd')='2013-02-12';
用时:1654ms

第二种查询语句

select * from test t where dtime between to_date('2012-02-12 00:00:00','yyyy-MM-dd HH24:mi:ss')
and to_date('2012-02-12 23:59:59','yyyy-MM-dd HH24:mi:ss');

用时:203ms

第三种查询语句

select * from test where dtime = to_date('2012-02-12 00:00:00','yyyy-MM-dd HH24:mi:ss');

用时:188ms

说明:字符进行比较是字节码的比较

date是整数比较

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言