scott中
2.创建一个过程,修改DEPT中的某一单位的单位名称,过程应包括异常处理;create or replace procedure
up_dept(s1_deptno dept.deptno%type,s1_dname dept.dname%type)
as begin
update dept set dname=s1_dname where deptno=s1_deptno;
exception
when no_data_found then
dbms_output.put_line('没有该部门数据');
end up_dept;无论输什么数据,异常都抛不出来
2.创建一个过程,修改DEPT中的某一单位的单位名称,过程应包括异常处理;create or replace procedure
up_dept(s1_deptno dept.deptno%type,s1_dname dept.dname%type)
as begin
update dept set dname=s1_dname where deptno=s1_deptno;
exception
when no_data_found then
dbms_output.put_line('没有该部门数据');
end up_dept;无论输什么数据,异常都抛不出来
其次你要想如果部门不存在,报异常。
你可以在update前面 家
select dname into 自己定义一个变量 from dept t where deptno=s1_deptno;
如果此时部门不存在 就会跳到异常处理
1. 下标索引指向一个被删除的元素,或是关联数组中不存在的元素
2. 一个select into语句没有检索到数据所以,你的语句不会引发NO_DATA_FOUND异常,是正常的。
up_dept(s1_deptno dept.deptno%type,s1_dname dept.dname%type)
as begin
update dept set dname=s1_dname where deptno=s1_deptno;
/*exception
when no_data_found then*/
if sql%notfound then
dbms_output.put_line('没有该部门数据');
end up_dept;