[转]oracle用instr代替like 效率比拼
t表中将近有1100万数据,很多时候,我们要进行字符串匹配,在SQL语句中,我们通常使用like来达到我们搜索的目标。但经过实际测试发现,like的效率与instr函数差别相当大。下面是一些测试结果:
SQL> set timing onSQL> select count(*) from t where instr(title,’手册’)>0;COUNT(*)———-65881Elapsed: 00:00:11.04SQL> select count(*) from t where title like ‘%手册%’;COUNT(*)———-65881Elapsed: 00:00:31.47SQL> select count(*) from t where instr(title,’手册’)=0;COUNT(*)———-11554580Elapsed: 00:00:11.31SQL> select count(*) from t where title not like ‘%手册%’;COUNT(*)———-11554580