1. 程式人生 > >Oracle 預定義異常

Oracle 預定義異常

declare
  v_name emp.ename%type;
  v_sal emp.sal%type:=&salary;
begin
  select ename,sal into v_name,v_sal from emp where sal=v_sal;
  dbms_output.put_line(v_name||'工資是:'||v_sal);
  exception
    when no_data_found then
      dbms_output.put_line('沒有該工資的員工!');
    when too_many_rows then
      dbms_output.put_line('多個員工具有該工資!');
    when others then
      dbms_output.put_line('其他異常!');
end; 
-- 7369 800 一個員工
-- 7521 7654 1250 多個員工
-- 沒有 8000 沒有員工
select * from emp;