欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Oracle用戶自定義異常實現(xiàn)過程解析

 更新時間:2020年09月29日 10:48:48   作者:勤快的懶羊羊  
這篇文章主要介紹了Oracle用戶自定義異常實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

注意:普通的查詢語句不會出現(xiàn)異常,只有使用into對變量進行賦值的時候才會發(fā)生異常

--系統(tǒng)變量: notfound --> if sql%notfund then 如果這個表達式為真,則 (增刪改)出錯
--,先自定義一個異常:no_result exception
        -- if sql%nofund then
        --excetpion
          --when no_result then
          --dbms……

用戶自定義異常寫在:declare里,如:

set serveroutput on
declare
no_result exception; --自定義異常
v_ssid student_test.sid%type;
begin
  update student_test set sex='男' where sid=1000002;  --沒有異常,報(自定義異常)插入為空的錯誤
 if SQL%NOTFOUND then
  RAISE no_result;
 end if;
exception
 when no_result then
  dbms_output.put_line('修改有誤!');
 when dup_val_on_index then
  dbms_output.put_line('系統(tǒng)異常,違反主鍵約束');
end;

如果修改語句修改為空,系統(tǒng)不會報錯,但會直接進入用戶自己定義的no_result異常里,

if SQL%NOTFOUND then
  RAISE no_result;
end if;

SQL%NOTFOUND是檢查更新語句是否更新成功,如果更新失敗,則notfound語句為真,
則使用raise語句跳轉(zhuǎn)到no_result異常執(zhí)行。

(dup_val_on_index)異常是系統(tǒng)異常,如果使用插入語句并且違反主鍵唯一性約束,則執(zhí)行dup_val_on_index異常。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論