您当前的位置:首页 > 文章摘抄 > 正文

if exists用法(exists用法)

关于if exists用法,exists用法这个很多人还不知道,今天菲菲来为大家解答以上的问题,现在让我们一起来看看吧!

1、exists可以说是oracle数据库开发中比较常见的用法,用exists可以提高sql的效率,可以取代in。

2、比如   a,b 关联列为 a.id = b.id,现在要取 a 中的数据,其中id在b中也存在:select * from a where exists(select 1 from b where a.id = b.id)现在要取 a 中的数据,其中id在b中   不存在:select * from a where not exists(select 1 from b where a.id = b.id)用法详解exists是判断exits后面的sql语句是否为真,若为真则整个sql句子成立,否则没有任何记录。

3、例子:select 1 from dual where exists (select 1 from dual where 2=1);上面的情况肯定是没有记录。

4、select 1 from dual where exists (select 1 from dual where 1=1);上面的情况是有记录返回的。

5、判断另外的表中是否包含某个表的外键记录。

6、例子: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中。

7、其实用in也可以实现同样的效果,但是in的话效率要低些,特别是碰上一些大表。

8、用exists和in的性能就体现出来了。

本文到此分享完毕,希望对大家有所帮助。


声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,谢谢。

上一篇: 潮流男装批发(广州十三行时尚潮流男装应该去哪里拿货(中档))

下一篇: 绿幽灵戴左手还是戴右手(绿幽灵带左手还是右手)



推荐阅读