Oracle数据库之SQL子查询详解(3)

发表于:2013-05-31来源:Csdn作者:一个小菜仔点击数: 标签:oracle
where ename =SMITH ) where job = ( select job from emp where ename =SMITH ) ; --去除销售部门 delete from emp where deptno = ( select deptno from dept where dname =SALES ) ; --DML语句中使用子

  where ename ='SMITH'

  )

  where job =

  (

  select job from emp where ename ='SMITH'

  )

  ;

  --去除销售部门

  delete from emp where deptno =

  (

  select deptno from dept

  where dname ='SALES'

  )

  ;

  --DML语句中使用子查询

  --insert中

  insert into employee (id,name,title,salary)

  select emptno,ename ,job,sal from emp;

  --update中

  update emp set (sal,comm)=

  (

  select sal,comm from emp

  where ename ='SMITH'

  )

  where job =

  (

  select job from emp where ename ='SMITH'

  )

  ;

  --去除销售部门

  delete from emp where deptno =

  (

  select deptno from dept

  where dname ='SALES'

  )

  ;

  4、在DDL语句中使用子查询

  通过select子查询来实现创建视图的方式来说明其使用方法

  需要注意的是在执行下面的sql语句之前,要对scott用户赋予创建视图的权利

  [sql] view plaincopyprint?

  SQL>conn / as sysdba

  SQL>grant create view to scott;

  SQL>conn / as sysdba

  SQL>grant create view to scott;

  [sql] view plaincopyprint?

  --创建视图并查询视图

  create or replace view dept10 as

  select empno,ename ,job,sal,deptno from emp

  where deptno = 10 order by empno;

  select * from dept10;

  --创建视图并查询视图

  create or replace view dept10 as

  select empno,ename ,job,sal,deptno from emp

  where deptno = 10 order by empno;

  select * from dept10;

  关于子查询的相关信息就到这里了。

原文转自:http://blog.csdn.net/kiritor/article/details/8782257