注意:普通的查詢語句不會(huì)出現(xiàn)異常,只有使用into對(duì)變量進(jìn)行賦值的時(shí)候才會(huì)發(fā)生異常
--系統(tǒng)變量: notfound --> if sql%notfund then 如果這個(gè)表達(dá)式為真,則 (增刪改)出錯(cuò)
--,先自定義一個(gè)異常: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; --沒有異常,報(bào)(自定義異常)插入為空的錯(cuò)誤
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)不會(huì)報(bào)錯(cuò),但會(huì)直接進(jìn)入用戶自己定義的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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- Oracle用decode函數(shù)或CASE-WHEN實(shí)現(xiàn)自定義排序
- 使用Python腳本zabbix自定義key監(jiān)控oracle連接狀態(tài)
- Oracle自定義脫敏函數(shù)的代碼詳解
- Oracle 自定義split 函數(shù)實(shí)例詳解
- ORACLE實(shí)現(xiàn)自定義序列號(hào)生成的方法
- 詳解Oracle自定義異常示例
- Oracle將查詢的結(jié)果放入一張自定義表中并再查詢數(shù)據(jù)
- oracle異常(預(yù)定義異常,自定義異常)應(yīng)用介紹