Oracle的例外分为预定义例外、非预定义例外和自定义例外。
1.Oralce常用预定义例外:
EXCEPTION
WHEN CURSOR_ALREADY_OPEN THEN-- ORA-06511 SQLCODE = -6511 游标已经打开
WHEN DUP_VAL_ON_INDEX THEN
-- ORA-00001 SQLCODE = -1 向唯一索引中插入重复数据
WHEN INVALID_CURSOR THEN
-- ORA-01001 SQLCODE = -1001 非法游标操作
WHEN INVALID_NUMBER THEN-- ORA-01722 SQLCODE = -1722 字符向数字转换失败
WHEN LOGIN_DENIED THEN
-- ORA-01017 SQLCODE = -1017
WHEN NO_DATA_FOUND THEN
-- ORA-01403 SQLCODE = +100 没有找到数据
WHEN NOT_LOGGED_ON THEN
-- ORA-01012 SQLCODE = -1012
WHEN PROGRAM_ERROR THEN
-- ORA-06501 SQLCODE = -6501 程序错误
WHEN STORAGE_ERROR THEN
-- ORA-06500 SQLCODE = -6500
WHEN TIMEOUT_ON_RESOURCE THEN
-- ORA-00051 SQLCODE = -51
WHEN TOO_MANY_ROWS THEN-- ORA-01422 SQLCODE = -1422 返回多行
WHEN TRANSACTION_BACKED_OUT THEN
-- ORA-00061 SQLCODE = -61
WHEN VALUE_ERROR THEN
-- ORA-06502 SQLCODE = -6502 数值转换错误
WHEN ZERO_DIVIDE THEN
-- ORA-01476 SQLCODE = -1476 被零除
WHEN OTHERS THEN-- 其它任何错误的处理
END;
2.非预定义例外:
目前我仅知道一个e_integrity sqlcode=-2291 数据不完整,违反数据完整性约束
3.自定义例外:
declare
e_notequal EXCEPTION;
begin
if 1!=2 then
raise e_notequal;
exception
when e_notequal then
raise_application_error('1不等于2');
end;