当前位置:   article > 正文

oracle中替换in命中索引,oracle优化or替换为in、exists、unionall的几种写法,测试没...

oracle in改union

oracle 优化or 替换为in、exists、union的几种写法,测试没有问题! 根据实际情况用选择相应的语句吧!如果有索引,or全表扫描,in 和not in 也要慎用,否则会导致全表扫描, select * from T_Pro_Product where bar_code = nnnmmm or name = nnnmmm or no =

oracle 优化or 替换为in、exists、union的几种写法,测试没有问题!

根据实际情况用选择相应的语句吧!如果有索引,or全表扫描,in 和not in 也要慎用,否则会导致全表扫描,

select *

from T_Pro_Product

where bar_code = 'nnnmmm'

or name = 'nnnmmm'

or no = 'nnnmmm';

select *

from T_Pro_Product

where 'nnnmmm' in (bar_code, name, no)

--忧化

select *

from T_Pro_Product t1

where exists

(select 1

from T_Pro_Product tt1

where t1.bar_code = 'nnnmmm'

union all

select 1

from T_Pro_Product tt2

where t1.no = 'nnnmmm'

union all

select 1 from T_Pro_Product tt3 where t1.name like 'n%')

--忧化

select *

from T_Pro_Product t1

where t1.id in (select id

from T_Pro_Product tt1

where t1.bar_code = 'nnnmmm'

union all

select id

from T_Pro_Product tt2

where t1.no = 'nnnmmm'

union all

select id

from T_Pro_Product tt3

where t1.name = 'nnnmmm') 本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/793127
推荐阅读
相关标签
  

闽ICP备14008679号