oracle中比like'%'更高效的模糊查询方法

这里记录一下一个比较好的模糊查询方法。转载自Oracle模糊查询方法,感谢原博主。

在Oracle中提供了instr(strSource,strTarget)函数,比使用'%关键字%'的模式效率高很多。

instr函数有三种情况:

instr(字段, '关键字')>0 相当于 字段 like '%关键字%'

instr(字段, '关键字')=1 相当于 字段 like '关键字%'

instr(字段, '关键字')=0 相当于 字段 not like '%关键字%'

例子: 

select  * from task a where instr(lower(a.code), 'tcc') > 0 

等价于: select * from task a where lower(a.code) like '%tcc%'.  

特殊用法:

select id, namefrom user where instr('101914, 104703', id) > 0;

它等价于

select id, namefrom user where id = 101914 or id = 104703;

猜你喜欢

转载自blog.csdn.net/ChauncyWu/article/details/79072473