set serveroutput on
declare
v_result number;
v_myexp exception;
pragma EXCEPTION_init(v_myexp,-20789); 自定义异常代码
begin
v_result:=11;
if v_result>10 and v_result<20 then
RAISE v_myexp;
-- DBMS_OUTPUT.PUT_LINE('iuewfiewfue');
end if;
exception
when others THEN
DBMS_OUTPUT.PUT_LINE('值范围错误');
dbms_OUTPUT.PUT_LINE('sqlcode='||sqlcode);
dbms_OUTPUT.PUT_LINE('sqlerrm='||sqlerrm);
end;
/
=====================
结果显示:
值范围错误
sqlcode=-20789
sqlerrm=ORA-20789:
如果需要自己设定,则必须在-20000——-20999之间
此方法无法定义异常信息。