oracle 取得exist 值,oracle exists and not exist

先看下面的例子:oracle中两个系统表.emp,dept.

example:

1:not exists(not in)

not exists:

这条语句返回select * from scott.dept d where e.deptno=d.deptno and d.deptno=10条件满足的结果集.也就是说,

返回的结果集中不存在d.deptno=10结果集的记录,即emp表中没有dept表中d.deptno=10的记录.

SQL> select empno,ename,deptno from scott.emp e where not exists(select * from scott.dept d where e.deptno=d.deptno and d.deptno=10);

EMPNO ENAME      DEPTNO

----- ---------- ------

7369 SMITH           20

7499 ALLEN           30

7521 WARD           30

7566 JONES           20

7654 MARTIN         30

7698 BLAKE           30

7788 SCOTT           20

7844 TURNER         30

7876 ADAMS          20

7900 JAMES           30

7902 FORD            20

11 rows selected

not in:

第一个where条件必须给定字段(deptno), 第二个sql语句中,必须明确给定要查询的字段是哪个(deptno).

SQL> select empno,ename,deptno from scott.emp e where deptno not in(select deptno from scott.dept d where e.deptno=d.deptno and d.deptno=10);

EMPNO ENAME      DEPTNO

----- ---------- ------

7369 SMITH           20

7499 ALLEN           30

7521 WARD           30

7566 JONES

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值