oracle EXISTS用法(exists用法)
你们好,最近小活发现有诸多的小伙伴们对于oracle EXISTS用法,exists用法这个问题都颇为感兴趣的,今天小活为大家梳理了下,一起往下看看吧。
1、select * from user where exists (select 1);
2、对user表的记录逐条取出,由于子查询中的select 1永远能返回记录行,
3、那么user表的所有记录都将被加入结果集,所以与 select * from user;是一样的
4、not exists与exists相反,
5、总的来说,如果A表有n条记录,那么exists查询就是将这n条记录逐条取出,
6、然后判断n遍exists条件
7、如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in:
8、例如:表A(小表),表B(大表)
9、1:
10、select * from A where cc in (select cc from B)效率低,
11、用到了A表上cc列的索引;
12、select * from A where exists(select cc from B where cc=A.cc)效率高,
13、用到了B表上cc列的索引。
14、2:
15、select * from B where cc in (select cc from A)效率高,
16、用到了B表上cc列的索引;
17、select * from B where exists(select cc from A where cc=B.cc)效率低用到了A表上cc列的索引。
18、not in 和not exists
19、如果描,没有用到索引;
20、而not extsts 的子查询依然能用到表上的索引。
以上就是exists用法这篇文章的一些介绍,希望对大家有所帮助。
免责声明:本文由用户上传,如有侵权请联系删除!
猜你喜欢
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
最新文章
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31
- 01-31