【发布时间】:2014-06-06 01:57:12
【问题描述】:
**UPDATE 修复了显示的错误,但它仍然无法正常运行。我需要创建一个用户定义的异常处理程序,它不允许将空值作为项目成本插入,但由于某种原因 raise 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;
/
【问题讨论】:
-
在 Oracle SqlPlus 或工作室中,您可以在 create 语句后添加
show errors。它会告诉你错误。不确定您使用的是什么数据库,但它可能有类似的东西。