导航:网站首页 >
oracle中not exists 是什么意思 , oracle数据库中exists的作用
oracle中not exists 是什么意思 , oracle数据库中exists的作用
匿名网友:
exists 是Oracle sql中的一个函数。
表示是否存在符合某种条件的记录。
如select * from A,Bwhere A.id=B.idand exists (SELECT * FROM AWHERE A.type LIKE 'S%')它和Oracle的另外一个函数IN很相似,你可以比较一下他们的用法,见下:http://www.blogjava.net/terry-zj/archive/2006/04/18/41662.html
匿名网友:
in的方式比较直观,exists则有些绕,而且in可以用于各种子查询,而exists好像只用于关联子查询其他子查询当然也可以用,可惜没意义。
由于exists是用loop的方式,所以,循环的次数对于exists影响最大,所以,外表要记录数少,内表就无所谓了,而in用的是hash join,所以内表如果小,整个查询的范围都会很小,如果内表很大,外表如果也很大就很慢了,这时候exists才真正的会快过in的方式。
not in 和not exists如果查询语句使用了not in 那么内外表都进行全表扫描,没有用到索引;而not extsts 的子查询依然能用到表上的索引。
所以无论那个表大,用not exists都比not in要快。
也就是说,in和exists需要具体情况具体分析,not in和not exists就不用分析了,尽量用not exists就好了。
匿名网友:
就是不在这个范围的意思select idfrom tablewhere name not exists(select 1from tablewhere name = 'aaa')也许你看不懂这个1的意思,不过在使用EXISTS的时候,通常都会使用1,它代表所查询出来的集合,等同于select name。
整个例子的意思是:查询name不等于aaa的所有ID。
不明白再问我,谢谢!
匿名网友:
exists可以说是oracle数据库开发中比较常见的用法,用exists可以提高sql的效率,可以取代in。
1. 比如 a,b 关联列为 a.id = b.id,现在要取 a 中的数据,其中id在b中也存在:select * from a where exists(select 1 from b where a.id = b.id)2. 现在要取 a 中的数据,其中id在b中 不存在:select * from a where not exists(select 1 from b where a.id = b.id)用法详解3. exists是判断exits后面的sql语句是否为真,若为真则整个sql句子成立,否则没有任何记录。
例子:select 1 from dual where exists (select 1 from dual where 2=1);上面的情况肯定是没有记录。
select 1 from dual where exists (select 1 from dual where 1=1);上面的情况是有记录返回的。
4. 判断另外的表中是否包含某个表的外键记录。
例子:select * from table_test awhere exists (select 1 from scott.carol_tmp where pps_master=a.pps_master);这个sql是要检查table_test中的pps_master是否在carol_tmp中。
其实用in也可以实现同样的效果,但是in的话效率要低些,特别是碰上一些大表。
用exists和in的性能就体现出来了。
问题推荐