Oracle中替换like的方法(Oracle优化)

昨天将oracle 9i的数据库迁移到oracle 10g,切换系统过去访问,很慢,原来是 like '%'的问题,网上搜了下,终于找到解决办法,可通过函数来替换like具体如下:
数据库中存储了海量的数据,当查询时使用like,速度明显变慢。我在做项目时,发现可以使用instr函数来取代like的作用。
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%'
转自
http://wolfware.bokee.com/4938460.html
Tags: 

延伸阅读

最新评论

发表评论