Oracle中替换like的方法
数据库中存储了海量的数据,当查询时使用like,速度明显变慢。
我在做项目时,发现可以使用instr函数来取代like的作用。
www.2cto.com
1.%a%方式:
Sql代码
select * from pub_yh_bm t
where instr(t.chr_bmdm,'2')>0
等份于:
Sql代码
select * from pub_yh_bm t
where t.chr_bmdm like '%2%'
2.%a方式:
Sql代码
select * from pub_yh_bm t
where instr(t.chr_bmdm,'110101')=length(t.chr_bmdm)-length('110101')+1
等份于:
Sql代码
select * from pub_yh_bm t
where t.chr_bmdm like '%110101'
www.2cto.com
3.a%方式:
Sql代码
select * from pub_yh_bm t
where instr(t.chr_bmdm,'11010101')=1
等份于:
Sql代码
select * from pub_yh_bm t
where t.chr_bmdm like '11010101%'
本文介绍如何使用 Oracle 的 INSTR 函数替代 LIKE 操作符进行字符串匹配查询,以此提高查询效率。通过三种不同场景的具体 SQL 示例,展示了 INSTR 函数在不同匹配条件下的应用。
385

被折叠的 条评论
为什么被折叠?



