一:捕获错误异常
1:通过捕获Oralce系统中的预定义的错误异常。
2:通过捕获自定义的错误异常。
二:捕获错误异常的方法
在Oralce数据库对象体内。
1:定义错误异常变量
User_Exception EXCEPTION;
2: Begin
--执行Sql语句
Exception
when others then
null;
End;
实例:
create or replace procedure P_User_Pro(AL_ORDER_ID in NUMBER) is
Order_Id_Null EXCEPTION;--自定义错误异常
if AL_ORDER_ID = 0 or isnull(AL_ORDER_ID ) then
RAISE Order_Id_Null ;
end if;
Begin
update User_Table_Name
set order_state = '01'
where order_id = AL_ORDER_ID;
Exception
when others then
RAISE_APPLICATION_ERROR(-20014, '更新单据状态失败!错误:'|| SQLCODE || SQLERRM);
return ;
end;
Exception
when Order_Id_Null then--捕获自定义的错误异常
RAISE_APPLICATION_ERROR(-20015, '单据ID不正确!错误:'|| SQLCODE || SQLERRM);
rollback;
when other then
RAISE_APPLICATION_ERROR(-20016, '更新单据状态失败!错误:'|| SQLCODE || SQLERRM);
rollback;
end P_User_Pro;
最后
以上就是明亮黄豆最近收集整理的关于Oracle中函数,过程和触发器等的错误异常处理的全部内容,更多相关Oracle中函数,过程和触发器等内容请搜索靠谱客的其他文章。
发表评论 取消回复