处理ORACLE异常
我需要处理 ORA-01400 错误 (无法将 NULL 插入 ("SCHEMA "."TABLE_NAME"."COLUMN_NAME") ) 使用异常句柄。
ORACLE预定义了一些异常,例如(ACCESS_INTO_NULL、ZERO_DIVIDE等),但显然没有为ORA-01400错误定义异常,我该如何处理这个特定的错误代码?
我需要这样的东西(接受其他建议)。
....
...
INSERT INTO MY_TABLE (CODE, NAME) VALUES (aCode,aName);
COMMIT;
EXCEPTION
WHEN NULL_VALUES THEN /* i don't know this value , exist?*/
Do_MyStuff();
WHEN OTHERS THEN
raise_application_error(SQLCODE,MY_OWN_FORMAT_EXCEPTION(SQLCODE,SQLERRM),TRUE);
END;
I need to handle the ORA-01400 error (cannot insert NULL into ("SCHEMA"."TABLE_NAME"."COLUMN_NAME") ) using a exception handle.
ORACLE Predefine a few Exceptions like (ACCESS_INTO_NULL, ZERO_DIVIDE and so on), but apparently does not define an Exception for the ORA-01400 error, how do I handle this particular error code?
I need something like this (other suggestions are accepted).
....
...
INSERT INTO MY_TABLE (CODE, NAME) VALUES (aCode,aName);
COMMIT;
EXCEPTION
WHEN NULL_VALUES THEN /* i don't know this value , exist?*/
Do_MyStuff();
WHEN OTHERS THEN
raise_application_error(SQLCODE,MY_OWN_FORMAT_EXCEPTION(SQLCODE,SQLERRM),TRUE);
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
预定义的 PL/SQL 异常对于 Oracle 来说是特殊的。你真的不能惹这些。当您想要拥有一组自己的预定义异常时,您无法像标准异常一样“全局”声明它们。相反,创建一个包含所有异常声明的异常包,并在您的应用程序代码中使用它。
示例:
现在使用包中定义的异常源
: http://www.orafaq.com/wiki/Exception
The pre-defined PL/SQL exceptions are special to Oracle. You really can't mess with those. When you want to have a set of predefined exceptions of your own you can't declare them "globally" like the standard ones. Instead, create an exceptions package which has all of the exception declarations and use that in your application code.
Example:
Now use the exception defined in the package
Source: http://www.orafaq.com/wiki/Exception
您可以定义自己的异常,例如变量(它们与其他变量具有相同的范围,因此您可以定义包异常等...):
you can define your own exceptions, like variables (they will have the same scope as other variables so you can define package exception, etc...):
您可以通过其代码来处理异常,如下所示:
You can handle exception by its code like this:
SQLERRM 显示 sql 错误消息
http://www.psoug.org/reference/exception_handling.html< /a>
SQLERRM shows the sql error message
http://www.psoug.org/reference/exception_handling.html