数据库中存储了海量的数据,当查询时使用like,速度明显变慢。我在做项目时,发现可以使用instr函数来取代like的作用。
1.%a%方式:
等份于:
2.%a方式:
等份于:
3.a%方式:
等份于:
1.%a%方式:
select * from pub_yh_bm t
where instr(t.chr_bmdm,'2')>0等份于:
select * from pub_yh_bm t
where t.chr_bmdm like '%2%'2.%a方式:
select * from pub_yh_bm t
where instr(t.chr_bmdm,'110101')=length(t.chr_bmdm)-length('110101')+1等份于:
select * from pub_yh_bm t
where t.chr_bmdm like '%110101'3.a%方式:
select * from pub_yh_bm t
where instr(t.chr_bmdm,'11010101')=1等份于:
select * from pub_yh_bm t
where t.chr_bmdm like '11010101%'
本文介绍了一种使用Instr函数替代SQL查询中Like操作的方法,以提高数据库查询效率。详细对比了不同查询条件(如%a%,%a,a%)下Instr函数与Like操作的等效使用,并说明了在何种情况下使用Instr能更有效地进行字符串匹配。
352

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



