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标准函数替换LIKE谓词的方法,通过具体的SQL示例展示了如何利用INSTR函数来提高查询效率,尤其是在视图上的查询。这种方法不仅能够保持LIKE谓词对索引的有效性,还能够显著提升查询速度。

1909

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



