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')
來源:http://www.cnblogs.com/yxwkf/p/4602143.html
