ORACLE 異常處理

2021-06-21 21:20:10 字數 996 閱讀 1546

一、

開發pl/sql程式時,需要考慮到程式執行時可能出現的各種異常,當異常出現時,或是中斷程式執行,或是使程式從錯誤中恢復,從而繼續執行。

常用的異常型別有:

no_data_found:沒有發現資料

too_many_rows:select into 語句查詢結果有多個資料行

others:可以捕捉所有異常,一般作為異常處理部分的最後乙個異常處理器

二、例子

-- v_code : 000 ,表示執行成功,其它表示執行失敗

create or replace procedure detector_plsql_exception(

v_deptno varchar2,

v_dname out varchar2,

v_code out varchar2,

v_msg out varchar2)as

begin

select d.dname into v_dname from dept d where d.deptno = v_deptno;

v_code := '000';

exception

when no_data_found then

v_code := '001';

v_msg := '找不到deptno為'||v_deptno||'的記錄';

when too_many_rows then

v_code := '002';

v_msg := 'deptno為'||v_deptno||'的記錄多於一條';

when others then

v_code := '999';

v_msg := '其它異常,'||sqlcode||','||sqlerrm;

--sqlcode:當前錯誤**

--sqlerrm:當前錯誤訊息檔案

end detector_plsql_exception;

..

Oracle 異常處理

1 什麼是異常 在pl sql 中的乙個警告或錯誤的情形都可被稱為異常。包括編譯時錯誤 pls 和執行時錯誤 ora 乙個異常通常包含乙個錯誤 和錯誤文字,分別指示異常的編號和具體錯誤資訊。異常情況處理 exception 是用來處理正常執行過程中未預料的事件,程式塊的異常處理預定義的錯誤和自定義錯...

Oracle 異常處理

異常處理 處理程式不可意料的操作,防止程式崩潰,起到友好提示 語法 exception when 異常型別 then 異常處理 異常型別 處理相關的異常 others 處理所有的異常 no data found 沒有找到資料 too many rows 返回資料行數過多自定義異常 實行彈窗的方式提示...

Oracle 異常處理

oracle 異常處理 異常是oracle資料庫中的pl sql 執行期間出現的錯誤。無論任何時候,當pl sql引擎執行 時,都可能會遇到異常。當產生異常時,pl sql會將程式控制轉到程式塊的異常處理部分。如果一場沒有被處理,那麼異常就會傳播,或者發往程式的呼叫者。如果使用者建立的程式塊沒有異常...