当与一个异常错误相关的错误出现时,就会隐含触发该异常错误。
用户定义的异常错误是通过显式使用 RAISE 语句来触发。
当引发一个异常错误时,控制就转向到 EXCEPTION块异常错误部分,执行错误处理代码。
SET serveroutput ON ;
declare
no_data exception ;
cursor c_emp is select e.ename from emp e ;--申明游标
v_emp emp.ename%type;
begin
open c_emp ; --打开游标
loop
fetch c_emp into v_emp
if c_emp%notfound then
raise exception;
end if ;
dbms_out.put_line(v_emp);
end loop ;
close c_emp ;
Exception
when no_data then
dbms_out.put_line('游标为空啦');
when others then
dbms_out.put_line('出现其他异常');
end ;