plsql触发器异常练习题
declaren number:请输入;beginfor i in reverse 1..length(n) loopdbms_output.put_line(substr(n,i,1));end loop;end;3.编写一个程序在 EMP 表查找姓名为 ALLEN 员工并获取 TOO_MANY_ROWS 和NO_DATA_FOUND 异常。5分declareV_sal number;beginexceptionwhen TOO_MANY_ROWS thendbms_output.put_line(sqlcode||sqlerrm);when NO_DATA_FOUND thendbms_output.put_line(sqlcode||sqlerrm);end;create or replace procedure sp_97(v_empno number,v_ename varchar2)isbegininsert into emp (empno,ename) values(V_empno,V_ename);end;写一个存储过程根据输入的参数,修改员工信息注如果只输入员工姓名那么就只修改姓名 ----隐藏条件 必须传入员工编号7566 张三如果输入多个值则修改员工的多个信息例如输入员工的姓名、工作、工资则要求7566 张三 经理 999把姓名、工作、工资信息都修改10分------ifcreate or replace procedure sp_97(v_emp emp%rowtype)isbeginif V_emp.ename is not null thenupdate emp set ename V_emp.ename where empnoV_emp.empno;end if;if V_emp.job is not null thenupdate emp set job V_emp.job where empnoV_emp.empno;end if;..................................end;7.查找出当前用户模式下每张表的记录数以scott用户为例结果应如下DEPT...................................4EMP...................................14BONUS.................................0SALGRADE.............................5提示查找用户下所有表名的sql为select * from user_tables;10分user_tables----数据字典 ----系统维护的一组表user ------用户dba ------管理员用户all -----所有用户select table_name from user_tables;declarev_sql varchar2(300); ----------------1 声明变量v_count number;beginfor i in (select table_name from user_tables) loopV_sql: select count(1) from ||i.table_name ;---2 定义动态sqlexecute immediate V_sql into V_count; -----3 立即执行动态sql 将结果交给变量dbms_output.put_line(i.table_name||.......||v_count);end loop;end;declarev_sql varchar2(300); ----------------1 声明变量v_count number;beginfor i in (select table_name from user_tables) loopV_sql: select count(1) from ||i.table_name ;---2 定义动态sqlexecute immediate V_sql into V_count; -----3 立即执行动态sql 将结果交给变量dbms_output.put_line(i.table_name||.......||v_count);end loop;end;8.某cc表数据如下c1 c2--------------1 西1 安1 的2 天2 气3 好……打印输出结果1 西安的2 天气3 好要求不能改变表结构及数据内容10分declarebeginfor i in (select distinct c1 from cc order by c1) loop --------------------外 1 2 3dbms_output.put(i.c1);for j in (select c2 from cc where c1i.c1) loop--------------------------内 1 西安的 2 天气 3 好dbms_output.put(j.c2);end loop;dbms_output.put_line();end loop;end;9.有一个表A( id, name ,age)和一个表 B(id , v_date , gxls)现在要求,当表A的数据变化时,将-----变化数据的id和更新时间以及更新的类型 插入到表B中, insert into b若insert 更新类型为 ‘i’,若update 更新类型为 ‘u’,若delete 更新类型为 ‘d’10分insert into a values(1,付浩浩,18)--触发触发器insert into b values(,sysdate,i) ---触发事件触发器的三种判断属性 inserting updating deleting行级触发器的两个数据 :old :newselect * from aselect * from btruncate table bt_97 ------ empcreate or replace trigger t_971beforeupdate or insert or deleteon afor each rowbeginif inserting theninsert into b values( :new.aid ,sysdate,i);elsif deleting theninsert into b values( :old.aid ,sysdate,d);elsif updating theninsert into b values( :new.aid ,sysdate,u);end if;end;2 付浩浩update 前 后insert 后 :newdelete 前 :oldselect * from bselect * from ainsert into a values(1,付浩浩,18)update a set age19delete from ab --日志---------------------------------------------------------------10.创建一个过程从emp表中带入雇员的姓名返回该雇员的薪水值。out参数10分create or replace procedure sP_97(V_ename in varchar2,V_sal out number)isbeginselect sal into V_sal from emp where enameV_ename;end;11.对直接上级是BLAKE的所有员工按照参加工作的时间加薪81年6月以前的加薪1081年6月以后的加薪5查询出姓名是BLAKE的员工编号10分declarebeginfor i in (select *from empwhere mgr(select empno from emp where enameBLAKE))loopif i.hiredate to_date(1981/6/1,yyyy/mm/dd) thenupdate emp set salsal*1.1 where empnoi.empno;elsif i.hiredate to_date(1981/6/1,yyyy/mm/dd) thenupdate emp set salsal*1.05 where empnoi.empno;elsenull;end if;end loop;end;12.编写一个PL/SQL程序块对名字以A或S开始的所有雇员按他们的基本薪水的10%加薪。10分declarebeginupdate emp set salsal*1.1 where ename likeA% or ename likeS%;end;----------------------------------------------------------------------------------------------------------------------------------------------