資料庫 異常處理

2021-09-12 06:12:55 字數 915 閱讀 9804

—處理步驟

declare

–宣告變數

begin

–處理邏輯

exception

–處理異常

when 異常1 then

。。。when 異常2 then

。。。when others then

。。。處理其他異常

end;

–常見異常

zero_divide : 除零異常

value_error : 型別轉換異常

too_many_row : 查詢多行資料,但是賦值給了rowtype

no_data_found : 沒有找到資料

— 例:

declare

vi number;

vrow emp%rowtype;

bagein

vi = 『aaa』; --型別轉換異常

vi := 8/0; --除零異常

select * into vrow from emp; --查詢多行資料,但是賦值給了rowtype

exception

when zero_divide then

dbm_output.put_line(『發生了除零異常』);

when value_error then

dbm_output.put_line(『發生了型別轉換異常』);

when too_many_row then

dbm_output.put_line(『查詢多行資料,但是賦值給了rowtype』);

when no_data_found then

dbm_output.put_line(『沒有找到資料』);

when others then

dbm_output.put_line(『發生其他異常』);

end;

Oracle資料庫 異常處理

oracle異常處理 在pl sql語句書寫時,需要處理的異常 不做異常處理時 declare v name emp.ename type v sal emp.sal type begin select ename,sal into v name,v sal from emp where empno...

資料庫之 異常處理篇

資料庫之 異常處理篇 預定義異常詳細列表 access into null 在未初化物件時出現 case not found 在case語句中的選項與使用者輸入的資料不匹配時出現 collection is null 在給尚未初始化的表或陣列賦值時出現 cursor already open 在使用...

Oracle資料庫的異常處理

一 說明 oracle資料庫底冊定義了很多異常,每個異常都有乙個唯一的編碼,這些異常之中,有一些是常見的,oracle給這些異常定義了名稱,可以直接使用,其他沒有名稱直郵編碼的不能直接使用。二 分類 1 預定義異常 既有編碼又有名稱的異常是預定義異常,此類異常可以直接使用 2 非預定義異常 有編碼但...