oracle 中 in 的用法

oracle 中 in 的用法,感觉不是很理解

哈尼露易丝
浏览 3205回答 2
2回答

qyy2499760117_叶子

EXISTS的执行流程select * from t1 where exists ( select null from t2 where y = x )可以理解为:for x in ( select * from t1 )loopif ( exists ( select null from t2 where y = x.x )thenOUTPUT THE RECORDend ifend loop对于in和exists的性能区别:如果子查询得出的结果集记录较少,主查询中的表较大且又有索引时应该用in,反之如果外层的主查询记录较少,子查询中的表大,又有索引时使用exists。其实我们区分in和exists主要是造成了驱动顺序的改变(这是性能变化的关键),如果是exists,那么以外层表为驱动表,先被访问,如果是IN,那么先执行子查询,所以我们会以驱动表的快速返回为目标,那么就会考虑到索引及结果集的关系了另外IN时不对NULL进行处理如:select 1 from dual where nullin (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 )loopif ( not exists ( that query ) ) thenOUTPUTend if;end;注意:NOT EXISTS与NOT IN不能完全互相替换,看具体的需求。如果选择的列可以为空,则不能被替换。  
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Oracle