系统中预设名字的异常错误语句¶
语法:
exception ::=
参数:
condition
错误的类型,这个异常条件是用来让存储过程的用户过滤感兴趣的异常,比如,当进行SELECT INTO操作时,如果返回的结果为0或者大于1,系统都会报告一个异常,这时,就可以使用相应的条件来过滤这些异常条件。其他未过滤的异常将会进入正常的路径,导致系统退出整个事务并跳回主循环。
statements
当发生异常时,需要执行的语句
说明:
目前PLOSCAR的异常条件分类尚未完善,多数异常没有名字。只能用以后将讲到的另一种方法捕捉。另外,others可以捕捉一切异常。
示例:预设名字的异常错误语句¶
-- 清理环境
DROP PROCEDURE proc;
DROP TABLE tab CASCADE;
create table tab(i int);
create or replace procedure proc as
declare
n int;
begin
select i into n from tab where i=1;
exception
when others then
begin
dbms_output.put_line('throw exception');
end;
end;
/
exec proc;
insert into tab values(1);
exec proc;
--删除过程
DROP PROCEDURE proc;
DROP TABLE tab CASCADE;