一、ORALCE自帶一些命名的系統異常,以下:app
Oracle Exception Name
Oracle Error
Explanation
中文註釋
DUP_VAL_ON_INDEX
ORA-00001
You tried to execute an INSERT or UPDATE statement that has created a duplicate value in a field restricted by a unique index.
插入或者更新語句,與惟一索引相沖突。
TIMEOUT_ON_RESOURCE
ORA-00051
You were waiting for a resource and you timed out.
等待資源超時
TRANSACTION_BACKED_OUT
ORA-00061
The remote portion of a transaction has rolled back.
遠程交易的部份交易已經回滾
INVALID_CURSOR
ORA-01001
You tried to reference a cursor that does not yet exist. This may have happened because you've executed a FETCH cursor or CLOSE cursor before OPENing the cursor.
引用一個不存在的遊標,如FETCH或者是CLOSE在其OPEN以前等。
NOT_LOGGED_ON
ORA-01012
You tried to execute a call to Oracle before logging in.
在登錄ORACLE以前執行調用錯誤
LOGIN_DENIED
ORA-01017
You tried to log into Oracle with an invalid username/password combination.
登錄時用戶名或者密碼非法。
NO_DATA_FOUND
ORA-01403
You tried one of the following: ide
1. You executed a SELECT INTO statement and no rows were returned. rest
2. You referenced an uninitialized row in a table. orm
3. You read past the end of file with the UTL_FILE package.
執行查詢無數據、引用一個末初使化的表、經過UTL_FILE包調用到尾的文件
TOO_MANY_ROWS
ORA-01422
You tried to execute a SELECT INTO statement and more than one row was returned.
採用SELECT INTO語句,但返回的記錄超過了1條
ZERO_DIVIDE
ORA-01476
You tried to divide a number by zero.
0爲除數
INVALID_NUMBER
ORA-01722
You tried to execute an SQL statement that tried to convert a string to a number, but it was unsuccessful.
將字符串轉換成數字,可是轉換失敗
STORAGE_ERROR
ORA-06500
You ran out of memory or memory was corrupted.
內存不足
PROGRAM_ERROR
ORA-06501
This is a generic "Contact Oracle support" message because an internal problem was encountered.
系統自身程序錯誤
VALUE_ERROR
ORA-06502
You tried to perform an operation and there was a error on a conversion, truncation, or invalid constraining of numeric or character data.
在執行轉換、截斷、非法轉換數據到文本出錯
CURSOR_ALREADY_OPEN
ORA-06511
You tried to open a cursor that is already open.
打開一個已經打開的遊標
索引
二、也能夠採用自定義的異常的名字:內存
declare資源
myexception exception;rem
begin字符串
if 1<>2 thenstring
raise myexception;
end if;
exception
when myexception then
/*注:raise_application_error的語法爲raise_application_error(erorcd in int,erortx in varchar 2),其中erorcd的值爲20001到20999*/
raise_application_error(20001,'my exception happens');
when others then
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
end
三、存儲過程可能要涉及到層層調用,所以在每一次都須要寫異常處理,這讓程序會更健壯。