oracle select嵌套查询的例子

发布时间:2020-03-21编辑:脚本学堂
分享几个oracle中select语句嵌套查询的例子,包括单行子查询、多行子查询、多列子查询等,有需要的朋友参考下。

本节内容:
oracle select嵌套查询
 
oracle数据库中嵌套查询的例子。
 

复制代码 代码示例:

--单行子查询
select ename,sal,deptno from emp where deptno=(select deptno from emp where ename='SCOTT')

select ename,sal,deptno from emp where deptno=(select deptno from emp where ename = 'SCOTT')

--多行子查询
select ename,sal,deptno,job from emp where job in (select distinct job from emp where deptno = 10)

select ename,sal,deptno,job from emp where sal>all(select sal from emp where deptno = 30)

select ename,sal from emp where deptno = 30

select ename,sal,deptno,job from emp where sal>any(select sal from emp where deptno = 30)

--多列子查询
select ename,sal,deptno,job from emp where (deptno,job)=(select deptno,job from emp where ename ='SMITH')

update emp
set sal=1500,comm=30 where ename = 'CLARK'

select ename,sal,comm from emp where ename = 'CLARK'

select ename,sal,comm,deptno from emp where(sal,nvl(comm,-1)) in (select sal,nvl(comm,-1) from emp where deptno =30)

select ename,sal,comm from emp where deptno=30

select ename,sal,comm,deptno from emp where sal in (select sal from emp where deptno = 30)and nvl(comm,-1)in(select nvl(comm,-1)from emp where deptno = 30)