为了账号安全,请及时绑定邮箱和手机立即绑定

oracle 中 in 的用法

oracle 中 in 的用法

哈尼露易丝 2016-06-15 08:50:56
oracle 中 in 的用法,感觉不是很理解
查看完整描述

2 回答

?
qyy2499760117_叶子

TA贡献188条经验 获得超91个赞

EXISTS的执行流程
select * from t1 where exists ( select null from t2 where y = x )
可以理解为:
for x in ( select * from t1 )loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
对于in和exists的性能区别:
如果子查询得出的结果集记录较少,主查询中的表较大且又有索引时应该用in,反之如果外层的主查询记录较少,
子查询中的表大,又有索引时使用exists。其实我们区分in和exists
主要是造成了驱动顺序的改变(这是性能变化的关键),如果是exists
,那么以外层表为驱动表,先被访问,如果是IN,那么先执行子查询,所以我们
会以驱动表的快速返回为目标,那么就会考虑到索引及结果集的关系了
另外IN时不对NULL进行处理如:
select 1 from dual where null
in (0,1,2,null)
为空
2.NOT IN与NOT EXISTS:
NOT EXISTS的执行流程
select .....from rollup R where not exists ( select 'Found' from title T where R.source_id = T.Title_ID);
可以理解为:
for x in ( select * from rollup )loop
if ( not exists ( that query ) ) then
OUTPUT
end if;
end;


注意:NOT EXISTS与NOT IN不能完全互相替换,看具体的需求。如果选择的列可以为
空,则不能被替换。

 

查看完整回答
2 反对 回复 2016-06-15
  • 2 回答
  • 0 关注
  • 3199 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信