like谓词可以用posstr标准函数替换,具体做法就是将a like '%b%' 替换为 posstr(a,'b')>0.
由于我在视图上like所以极慢,所以我用posstr快很多。但是like对索引还是很有效果的。
下面是oracle的函数
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%'
本文介绍了一种使用POSSTR函数或INSTR函数替代LIKE谓词的方法,这种方法可以提高查询效率,尤其是在视图上的查询。通过具体的Oracle函数示例,展示了如何进行转换以及其等效性。
2462

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



