Oracle用instr代替like
Oracle表中将近有1100万数据,很多时候,我们要进行字符串匹配,在SQL语句中,我们通常使用like来达到我们搜索的目标。但经过实际测试发现,like的效率与instr函数差别相当大。下面是一些测试结果:
SQL> set timing on
SQL> select count(*) from t where instr(title,’手册’)>0;
COUNT(*)
———-
65881
Elapsed: 00:00:11.04
SQL> select count(*) from t where title like ‘%手册%’;
COUNT(*)
———-
65881
Elapsed: 00:00:31.47
SQL> select count(*) from t where instr(title,’手册’)=0;
COUNT(*)
———-
11554580
Elapsed: 00:00:11.31
SQL> select count(*) from t where title not like ‘%手册%’;
COUNT(*)
———-
11554580
注:
instr(title,’手册’)>0 相当于like
instr(title,’手册’)=0 相当于not like
相关推荐
娜娜 2020-07-28
LuoXinLoves 2020-06-10
Justdoit00 2020-06-01
Carlos 2020-03-06
LuoXinLoves 2020-02-24
昊 2019-12-11
holyrong 2014-07-18
qianhaohong 2018-05-18
vipzhangcong 2019-06-26
Lifeisforsharing 2019-05-16
sunbocong 2012-09-27
jbossllx 2018-11-21
MySQL 2014-12-06
拾毅者 2018-05-23
TongFn 2014-06-11
kiddwyl 2013-07-04
天涯客Blog 2012-12-09