异常处理程序不提高

时间:2014-04-21 22:14:36

标签: exception plsql handler

** UPDATE修复了显示的错误,但仍然没有按照我的意愿运行。我需要创建一个用户定义的异常处理程序,它不允许插入空值作为项目成本,但由于某种原因,提升missing_cost没有运行。我将item_id和item_cost设置为用户定义,但我认为它没有正确传递?

表是:

pitem
{item_id number;
 item_name char(20);
 item_desc char(20);
 retail_price number(10,2);
 item_cost number(10,2);
 category char(10);
}

和...

pitem_audit
{item_id number;
message char(80);
}

提前感谢!

create or replace procedure update_item_cost (iItemId INTEGER, 
fNewcost NUMBER) as fCurCost NUMBER(10,2);
missing_cost EXCEPTION;

item_id pitem.item_id%type :=&item_id;
item_cost pitem.item_cost%type := &item_cost;


begin
    select item_cost into fCurCost from pitem
    where item_id=iItemid;

    if fCurCost IS null then
        raise missing_cost;
    else
        update pitem set item_cost=fNewCost
        where item_id=iItemid;
    end if;

commit;
end;

exception
    when no_data_found then
    insert into pitem_audit
        values(iItemid, 'Invalid Item identifier.');
    commit;
    when missing_cost then
    insert into pitem_audit
        values(iItemid, 'Item Cost is null.');
    commit;
    when others then
    rollback;
    insert into pitem_audit
        values(iItemid, 'Miscellaneous error.');
    commit;
end update_item_cost;
/

1 个答案:

答案 0 :(得分:0)

这是程序的结构:

procedure <procname>
   (<parameters>)
as
   <declarations>
begin
   <body to execute>
exception
   <exception handlers>
end <procname>;

在您的情况下,您还有一个额外的end;

procedure <procname>
   (<parameters>)
as
   <declarations>
begin
   <body to execute>
end; <-- this is incorrect
exception
   <exception handlers>
end <procname>;