1、系統預定義異常
no_data_found
case_not_found
cursor_already_open
invalid_number
--no_data_found異常
set
serveroutput on;
--&no表示從控制台輸入參數
declare
v_ename
varchar2(30);--定義字元串變量
v_sal number(7,2);
begin
select
ename,sal into v_ename,v_sal from emp where empno=&no;
dbms_output.put_line(‘雇員名:‘||v_ename||‘工資:‘||v_sal);
exception
when no_data_found then
dbms_output.put_line(‘沒有找到該雇員号!‘);
end;
/
2、使用者自定義異常
create or replace
procedure ex_test(spno number) is
--定義一個例外
myexp
exception;
update emp set sal = sal +1000 where empno =
spno;
if sql%notfound then --表示sql語句沒有執行更新操作
raise myexp;--觸發異常
end if;
exception
when myexp
then
dbms_output.put_line(‘沒有更新任何使用者‘);