时间:2022-06-11 10:10:40 | 栏目:Oracle | 点击:次
PL/SQL块中只能直接嵌入SELECT、DML(INSERT,UPDATE,DELETE)以及事务控制语句(COMMIT,ROLLBACK,SAVEPOINT),
而不能直接嵌入DDL语句(CREATE,ALTER,DROP)和DCL语句(GRANT,REVOKE)
1、嵌入SELECT语句
使用SELECT INTO语句时,必须要返回一条数据,并且只能返回一条数据。
v_ename emp.ename%type; v_sal emp.sal%type; select ename,sal into v_ename,v_sal from emp where empno=&no;
2、嵌入insert子句。
v_deptno emp.deptno%type:=&no; insert into employee select * from emp where deptno=v_deptno;
3、更新数据
v_ename emp.ename%type:='&name'; update emp set (sal,comm) = (select sal,comm from emp where ename=v_ename) where job = (select job from emp where ename=v_ename)
4、删除数据
v_ename emp.ename%type:='&name'; delete from emp where deptno=(select deptno from emp where ename=v_ename);