--例子:
declare
e_integerity exception;
e_no_employee exception;
pragma exception_init(e_integerity,-2291);
begin
update scott.emp set deptno=40 where empno=-1;
if sql%notfound then
raise e_no_employee;
end if;
exception
when e_integerity then
dbms_output.put_line('该部门不存在');
when e_no_employee then
dbms_output.put_line('该员工不存在');
end;
刚学这个,感觉有些代码没有完全懂,希望得到解释,谢谢
declare
e_integerity exception;
e_no_employee exception;
pragma exception_init(e_integerity,-2291);
begin
update scott.emp set deptno=40 where empno=-1;
if sql%notfound then
raise e_no_employee;
end if;
exception
when e_integerity then
dbms_output.put_line('该部门不存在');
when e_no_employee then
dbms_output.put_line('该员工不存在');
end;
刚学这个,感觉有些代码没有完全懂,希望得到解释,谢谢
给oracle系统错误-2291指定一个异常名字e_integerity;这样就可以在exception子块中用这个名字来捕获异常。update scott.emp set deptno=40 where empno=-1;
if sql%notfound then
raise e_no_employee;
这里是说如果前面的update语句没有更新任何记录,就抛出异常e_no_employee