前端之家收集整理的这篇文章主要介绍了
如何捕获和处理特定的Oracle异常?,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
从
this和
this我猜,ORA-00955没有预定义的命名系统异常.
如何重写以下内容以仅捕获错误ORA-00955?
begin
EXECUTE IMMEDIATE 'CREATE SEQUENCE S_TEST START WITH 1 INCREMENT BY 1';
exception when OTHERS then
Null;
end;
BTW是否有任何语法只通过提供错误代码来捕获错误?
@H_
404_8@
你有两个选择:
直接通过编号参考例外:
BEGIN
EXECUTE IMMEDIATE 'CREATE SEQUENCE S_TEST START WITH 1 INCREMENT BY 1';
EXCEPTION
WHEN OTHERS THEN
IF sqlCODE = -955 THEN
NULL; -- suppresses ORA-00955 exception
ELSE
RAISE;
END IF;
END;
其他选项是使用EXCEPTION_INIT Pragma指令将已知的Oracle错误号绑定到用户定义的异常;
DECLARE
name_in_use exception; --declare a user defined exception
pragma exception_init( name_in_use,-955 ); --bind the error code to the above
BEGIN
EXECUTE IMMEDIATE 'CREATE SEQUENCE S_TEST START WITH 1 INCREMENT BY 1';
EXCEPTION
when name_in_use then
null; --suppress ORA-00955 exception
END;
BTW Is there any Syntax to catch errors by just providing the error-codes?
是的,我在第一个例子中证明了这一点
进一步阅读以下变化:
> Oracle Reference Documentation on Handling PL/SQL Exceptions