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. js开发思路

    $.ui = $.ui || {}; var version = $.ui.version = "1.12.1"; // 是否为ie浏览器 var ie = $.ui.ie = ! ...

  2. LintCode: Binary Tree Postorder Traversal

    C++,递归 /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *righ ...

  3. 微信小程序 - debug(调试)

    微信小程序调试的方式是基于Chrome. 1. 常见console.log调试(可以具体参考console.log这个函数使用,它可不止这一个作用!) 2.使用NETWORK(我们可以查询到访问了那些 ...

  4. 使用electron+Js开发夸平台(Linux、Win、Mac)的桌面应用程序

    一.开源地址: https://github.com/electron/electron 二.官方网站: https://electron.atom.io/ 三.案例

  5. bootstrap找不到glyphicons-halflings-regular.woff2

    在vue2的项目中是用bootstrap,提示下面的字体文件找不到 http://localhost:8080/static/fonts/glyphicons-halflings-regular.wo ...

  6. vuejs 过渡效果

    过渡效果 https://cn.vuejs.org/v2/guide/transitions.html http://router.vuejs.org/zh-cn/advanced/transitio ...

  7. javascript数组去重复

    数组去重 知乎上看到有人去腾讯面试,然后发了面试的js题目,有一个是数组去重 我的土办法 var arr = ['a', 'g', 'q', 'd', 'a', 'e', 'q']; console. ...

  8. C语言之函数调用06—彩球排列

    //函数调用+递归法 /* ========================================================== 题目:将4个红球,3个白球.3个黄球排成一排,共同拥有 ...

  9. python binascii模块详解

    ['Error', 'Incomplete', 'b2a_hex', 'hexlify' #Hexadecimal representation of binary data. 字符串转16进制'a2 ...

  10. java获取文件流

      CreateTime--2017年9月1日14:49:21 Author:Marydon servlet获取文件流的两种方式 方式一:使用绝对路径(推荐使用) import java.io.Inp ...