UND Òì³£, TOO_MANY_ROWS ½øÐд¦Àí.
declare
v_sal employees.salary%type;
begin
select salary into v_sal from employees where employee_id = 100;
if(v_sal < 300) then
update employees set salary = salary + 100 where employee_id = 100;
else
dbms_output.put_line('¹¤×Ê´óÓÚ300');
end if;
exception
when no_data_found then
dbms_output.put_line('δÕÒµ½Êý¾Ý');
when too_many_rows then
dbms_output.put_line('Êä³öµÄÊý¾ÝÐÐÌ«¶à');
end;
3. ´¦Àí·ÇÔ¤¶¨ÒåµÄÒì³£´¦Àí: "Î¥·´ÍêÕûÔ¼ÊøÌõ¼þ"
declare
--1. ¶¨ÒåÒì³£
temp_exception exception;
--2. ½«Æä¶¨ÒåºÃµÄÒì³£Çé¿ö£¬Óë±ê×¼µÄ ORACLE ´íÎóÁªÏµÆðÀ´£¬Ê¹Óà EXCEPTION_INIT Óï¾ä
PRAGMA EXCEPTION_INIT(temp_exception, -2292);
begin
delete from employees where employee_id = 100;
exception
--3. ´¦ÀíÒì³£
when temp_exception then
dbms_output.put_line('Î¥·´ÍêÕûÐÔÔ¼Êø!');
end;
4. ×Ô¶¨ÒåÒì³£: ¸üÐÂÖ¸¶¨Ô±¹¤¹¤×Ê£¬Ôö¼Ó100£»Èô¸ÃÔ±¹¤²»´æÔÚÔòÅ׳öÓû§×Ô¶¨ÒåÒì³£: no_result
declare
--×Ô¶¨ÒåÒì³£
no_result exception;
begin
update employees set salary = salary + 100 where employee_id = 1001;
--ʹÓÃÒþʽÓαê, Å׳ö×Ô¶¨ÒåÒì³£
if sql%notfound then
raise no_result;
end if;
exception
--´¦Àí³ÌÐòÅ׳öµÄÒì³£
when no_result then
dbms_output.put_line('¸üÐÂʧ°Ü');
end;