ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

PL/SQLÒì³£´íÎó´¦Àí(¶þ)
2014-11-23 19:02:38 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:54´Î
Tags£ºPL/SQL Òì³£ ´íÎó ´¦Àí
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;

Ê×Ò³ ÉÏÒ»Ò³ 1 2 ÏÂÒ»Ò³ βҳ 2/2/2
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºPL/SQLÓαêµÄʹÓà ÏÂһƪ£º¡¾sqlÓï¾ä¡¿ºÃÓõÄsqlÓï¾ä¨DÊʺÏ×..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ: