oracle的异常
一、在plsql中,oracle自带的Exceptions如下:
Exception | Oracle Error | SQLCODE Value |
ACCESS_INTO_NULL | ORA-06530 | -6530 |
CASE_NOT_FOUND | ORA-06592 | -6592 |
COLLECTION_IS_NULL | ORA-06531 | -6531 |
CURSOR_ALREADY_OPEN | ORA-06511 | -6511 |
DUP_VAL_ON_INDEX | ORA-00001 | -1 |
INVALID_CURSOR | ORA-01001 | -1001 |
INVALID_NUMBER | ORA-01722 | -1722 |
LOGIN_DENIED | ORA-01017 | -1017 |
NO_DATA_FOUND | ORA-01403 | +100 |
NOT_LOGGED_ON | ORA-01012 | -1012 |
PROGRAM_ERROR | ORA-06501 | -6501 |
ROWTYPE_MISMATCH | ORA-06504 | -6504 |
SELF_IS_NULL | ORA-30625 | -30625 |
STORAGE_ERROR | ORA-06500 | -6500 |
SUBSCRIPT_BEYOND_COUNT | ORA-06533 | -6533 |
SUBSCRIPT_OUTSIDE_LIMIT | ORA-06532 | -6532 |
SYS_INVALID_ROWID | ORA-01410 | -1410 |
TIMEOUT_ON_RESOURCE | ORA-00051 | -51 |
TOO_MANY_ROWS | ORA-01422 | -1422 |
VALUE_ERROR | ORA-06502 | -6502 |
ZERO_DIVIDE | ORA-01476 | -1476 |
when others then
if sqlcode=[需要处理错误的oracle error code value] then
...
end if
二、自定义异常,示例如下:
--申明
DECLARE inventory_too_low EXCEPTION;
--抛出
IF order_rec.qty>inventory_rec.qty THEN
RAISE inventory_too_low;
END IF
--截获
EXCEPTION
WHEN inventory_too_low THEN
END;