1.彈出錯(cuò)誤框:
示例代碼:
declare v_count number; begin select count(*) into v_count from dept; if v_count 10 then raise_application_error(-20001,'數(shù)量小于10'); end if; end;
執(zhí)行結(jié)果:
2.控制臺(tái)顯示:
示例代碼:
declare v_count number; my_exp exception; begin select count(*) into v_count from dept; if v_count 10 then raise my_exp; end if; exception when my_exp then dbms_output.put_line('數(shù)量小于10'); when others then dbms_output.put_line('其他異常'); end;
執(zhí)行結(jié)果:
PS:ORACLE 用戶自定義異常小例子
CREATE OR REPLACE PROCEDURE test_Exception_byLeejin ( ParameterA IN varchar, ParameterB IN varchar, ErrorCode OUT varchar --返回值,錯(cuò)誤編碼 ) AS /*以下是一些變量的定義*/ V NUMBER; V nvarchar(); V NUMBER; APP_EXP EXCEPTION; --自定義異常 BEGIN ErrorCode :=''; IF (ParameterA=ParameterB) THEN ErrorCode := 'ParameterA = ParameterB'; RAISE APP_EXP; -- 拋出異常 END IF; EXCEPTION WHEN APP_EXP THEN --在處理異常 RAISE_APPLICATION_ERROR(-,ErrorCode); WHEN OTHERS THEN RAISE_APPLICATION_ERROR(-,'未知異常'); END;
標(biāo)簽:固原 周口 甘肅 武漢 青島 承德 和田 開封
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解Oracle自定義異常示例》,本文關(guān)鍵詞 詳解,Oracle,自定義,異常,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。