exists 是Oracle sql中的一个函数。表示是否存在符合某种条件的记录。如

select * from A,B 
where A.id=B.id 
and exists (SELECT * 
FROM A 
WHERE A.type LIKE 'S%')

它和Oracle的另外一个函数IN很相似,你可以比较一下他们的用法,见下:

1 性能上的比较比如Select * from T1 where x in ( select y from T2 )
执行的过程相当于:
select * 
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
即分别先查寻两个表,对做联合查询(本质联合查询)
相对的

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
表 T1 不可避免的要被完全扫描一遍

即循环外表,在逐个比较内表

分别适用在什么情况?
以子查询 ( select y from T2 )为考虑方向
如果子查询的结果集很大需要消耗很多时间,但是T1比较小执行( select null from t2 where y = x.x )非常快,那么exists就比较适合用在这里
相对应得子查询的结果集比较小的时候就应该使用in.

以后要注意凡是这样的比较问题,一般答案都不是绝对的,要分情况

 in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询。一直以来认为exists比in效率高的说法是不准确的。
 如果查询的两个表大小相当,那么用in和exists差别不大。

如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in:

---转载自http://blog.csdn.net/hakunamatata2008/article/details/4239831

oracle中exists和in的比较的更多相关文章

  1. Oracle中exists与in的区别

    有两个简单例子,以说明 "exists"和"in"的效率问题 1) select * from T1 where exists(select 1 from T2 ...

  2. Oracle中exists替代in语句

    大家都知道exists的速度要比in的速度快,也知道exists函数返回一个布尔值,也就是说exists函数里最后要是 a.id =b.id类似这种方式结束. 例如: SELECT * FROM TB ...

  3. oracle中exists 和 in 的区别

    1)用IN select * from A where id in(select id from B); 以上查询使用了in语句,in()只执行一次,它查出B表中的所有id字段并缓存起来.注意,是缓存 ...

  4. <正则吃饺子> :关于oracle 中 exists 、not exists 的简单使用

    话不多说,简单的总结而已.网络上很多很详细介绍. 例如,博文:http://blog.csdn.net/zhiweianran/article/details/7868894  当然这篇也是转载的,原 ...

  5. Oracle中没有 if exists(...)

    对于Oracle中没有 if exists(...) 的语法,目前有许多种解决方法,这里先分析常用的三种,推荐使用最后一种 第一种是最常用的,判断count(*)的值是否为零,如下declare  v ...

  6. oracle中的exists 和not exists 用法 in与exists语句的效率问题

    博文来源(oracle中的exists 和not exists 用法):http://chenshuai365-163-com.iteye.com/blog/1003247 博文来源(  in与exi ...

  7. Oracle中not exists 与not in 的使用情况

    1.在oracle11g以上版本,oracle已经做了优化,能够自动将in优化成exists方式,因此oracle11g以上版本,使用in和exists效果是一样的. 2.在oracle中,使用not ...

  8. ORACLE 中IN和EXISTS比较

    ORACLE 中IN和EXISTS比较 EXISTS的执行流程      select * from t1 where exists ( select null from t2 where y = x ...

  9. oracle 中的exists 和 in 效率问题

    oracle中的 exists 和 in 的效率问题 --------------------------------------------------------------- +++++++++ ...

随机推荐

  1. 【Linux】好玩的linux命令

    Linux里面有很多有趣的东西,这篇文章整理了一些.摘录一下: 1. sl 命令 你会看到一辆火车从屏幕右边开往左边...... 安装  $ sudo apt-get install sl 运行  $ ...

  2. unity3d与web网页通信

    总结一下: Unity3D 中的 C# 和 JavaScript 脚本之间是可以互相访问并交互的,但是要求这些被访问和操作的 C# 和 JavaScript 组件必须放在名为 Standard Ass ...

  3. Iterator接口用法

    1.所有实现Collection接口的容器类都有一个iteractor方法,用于返回一个实现了Iteractor接口的对象, 2.Iteractor对象成为迭代器,用以实现对容器内元素的遍历操作 3. ...

  4. SLF4J warning or error messages and their meanings

    来自:http://www.slf4j.org/codes.html#StaticLoggerBinder The method o.a.commons.logging.impl.SLF4FLogFa ...

  5. shell 截取变量的字符串(转)

    来自:http://blog.sina.com.cn/s/blog_7c95e5850100zpch.html 假设有变量 var=http://www.linuxidc.com/test.htm 一 ...

  6. 使用 axios 详解

    Vue.js 1.0 我们常使用 vue-resource (官方ajax库), Vue 2.0 发布后作者宣告不再对 vue-resource 进行更新, 推荐我们使用 axios (基于 Prom ...

  7. .NET网址

    1.爱整理:http://www.aizhengli.com/

  8. 合并果子(NOIP2004)

    合并果子(NOIP2004)[问题描述]在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆.每一次合并,多多可以把两堆果子合并到一起,消耗的体 ...

  9. (原)使用tensorboard显示loss

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/7416551.html 参考网址: http://blog.csdn.net/jerry81333/ar ...

  10. (原+转)Ubuntu16.04软件中心闪退及wifi消失

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6321889.html 参考网址: http://blog.csdn.net/felcon/articl ...