开发者

PL/SQL exception handling with procedures

create or replace procedure UPD_DEP 
    (dd_name in dept.dname%type, --department which has to be updated
    d_name in dept.dname%type)   --name to which the first parameter has to be updated 
is 
abc_exception exception;
begin
if (dname<>dd_name) THEN
  raise abc_exception; 
end if;
update dept
set dname=d_name
where dname=dd_name;  
commit;
EXCEPTION
WHEN  abc_exception THEN
dbms_output.put_line('department not present which u want to be updated');
end upd_dep;

Error at line 9: PL/SQL: Statement ignored

  • 7 if (dname<>dd_name) THEN (line 7)
  • 开发者_JS百科
  • 8 raise abc_exception; (line 8)
  • 9 end if; (line 9)
  • 10 update dept (line 10)
  • 11 set dname=d_name (line 11)


In line 7, you reference dname as a variable, but there is no variable with that name. My first assumption was that you meant that to be d_name, the second parameter to the function, but that doesn't make sense since you would then be skipping the update unless the two values were equal.

Based on what you are doing in the exception handler, I guess that the if is an attempt to check for whether rows exist to be updated, and the dname is an effort to reference the actual column in the table. But you can't just reference table columns in the middle of PL/SQL code at whim -- how is the compiler supposed to understand this reference?

Besides, the best way to check whether an update would affect any rows is to do it and test the result.

create or replace procedure UPD_DEP
(dd_name in dept.dname%type, --department which has to be updated
d_name in dept.dname%type) --name to which the first parameter has to be updated
is
begin

update dept
set dname=d_name
where dname=dd_name;

if SQL%FOUND then
  commit;
else
  dbms_output.put_line('department not present which u want to be updated');
end if;

end upd_dep;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜