--处理非预定义例外
--非预定义例外用于处理与预定义例外无关的oracle错误。
--使用预定义例外,只能处理21个oracle错误。而当开发的时候,可能会遇到其他的一些oracle错误
--比如:执行dml语句时,违反了约束规则
--处理自定义例外
--自定义例外与oracle错误没有任何关联,它是有开发人员为特定情况所定义的例外
使用例外函数
[list]
错误号:-12899,错误信息:ORA-12899: 列 "IRDP"."COMMUNITYTYPE"."WITHDRAWN" 的值太大 (实际值: 3, 最大值: 2)
[/list]
--非预定义例外用于处理与预定义例外无关的oracle错误。
--使用预定义例外,只能处理21个oracle错误。而当开发的时候,可能会遇到其他的一些oracle错误
--比如:执行dml语句时,违反了约束规则
declare
e_integrity exception;
pragma exception_init(e_integrity,-12899);
begin
update communitytype t
set t.withdrawn = '132'
where t.community_type_id = 'ebook';
exception
when e_integrity then
dbms_output.put_line('withdrawn标志位长度不合法');
end;
。
--处理自定义例外
--自定义例外与oracle错误没有任何关联,它是有开发人员为特定情况所定义的例外
declare
e_no_comtype exception;
begin
update communitytype t
set t.english_name = '1'
where t.community_type_id = 'abcdefg';
if sql%notfound then
raise e_no_comtype;
end if;
exception
when e_no_comtype then
dbms_output.put_line('没有找到数据');
end;
使用例外函数
declare
e_integrity exception;
pragma exception_init(e_integrity,-12899);
begin
update communitytype t
set t.withdrawn = '132'
where t.community_type_id = 'ebook';
exception
when e_integrity then
dbms_output.put_line('错误号:'||sqlcode||',错误信息:'||sqlerrm);
end;
[list]
错误号:-12899,错误信息:ORA-12899: 列 "IRDP"."COMMUNITYTYPE"."WITHDRAWN" 的值太大 (实际值: 3, 最大值: 2)
[/list]