插入或更新销售项目后 oracle 触发器
我有这个表,它代表一个弱实体,是一个用于介绍订购项目的典型表: 插入 ITEM_FORNECIMENTO 值(a_orderId、a_prodId、a_prodQtd、a_buyPrice);
我希望我的触发器更新最后一列(没有 iva 的产品总价)来执行以下操作:totalPrice=totalPrice*(1+(iva/100),每次我在该表上插入或更新条目时。
所以,我想出了这个,但在使用新值和旧值时我完全错误。
create or replace
trigger t_replaceTotal
after insert or update of id_prod,qtd_if,prec_total_if on item_fornecimento
for each row
declare
iva produto.iva_prod%type;
idProd produto.id_prod%type;
r_old item_fornecimento.prec_total_if%type:=null;
r_new item_fornecimento.prec_total_if%type:=null;
begin
select iva_prod,id_prod into iva,idprod from produto p where p.id_prod = id_prod;
r_old:= :old.prec_total_if;
r_new:= :new.prec_total_if;
update item_fornecimento item set prec_total_if = r_old * (1+(iva/100)) where item.id_prod = idprod;
end;
有人可以帮助我重写此代码吗?ORA-01422:精确获取返回的行数超过了请求的行数。 ORA-06512: 在“FUSION.T_REPLACETOTAL”,第 8 行 ORA-04088: 执行触发器“FUSION.T_REPLACETOTAL”期间出错
I have this table that represents a weak entity and is a typical table for introducing items ordered:
insert into ITEM_FORNECIMENTO values (a_orderId,a_prodId,a_prodQtd, a_buyPrice);
I want my trigger to update the last column (the total price of products WITHOUT iva) to do this : totalPrice= totalPrice*(1+(iva/100), each time I insert or update an entry on that table.
so, I came up with this, but I'm totally wrong when it comes to work with new and old values.
create or replace
trigger t_replaceTotal
after insert or update of id_prod,qtd_if,prec_total_if on item_fornecimento
for each row
declare
iva produto.iva_prod%type;
idProd produto.id_prod%type;
r_old item_fornecimento.prec_total_if%type:=null;
r_new item_fornecimento.prec_total_if%type:=null;
begin
select iva_prod,id_prod into iva,idprod from produto p where p.id_prod = id_prod;
r_old:= :old.prec_total_if;
r_new:= :new.prec_total_if;
update item_fornecimento item set prec_total_if = r_old * (1+(iva/100)) where item.id_prod = idprod;
end;
Could someone please help rewriting this code? I'm getting the error: ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "FUSION.T_REPLACETOTAL", line 8
ORA-04088: error during execution of trigger 'FUSION.T_REPLACETOTAL'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您试图从表中获取每一行,因为您正在将列 (id_prod) 与其自身匹配。我怀疑您想使用 :new.id_prod 或 :old.id_prod。
接下来,将其设置为 BEFORE INSERT/UPDATE 触发器,并将 UPDATE 语句替换为
否则,您将遇到混乱的变异表错误。
The problem is that you are trying to fetch every row from the table because you are matching a column (id_prod) to itself. I suspect you want to use :new.id_prod or :old.id_prod.
Next, make this a BEFORE INSERT/UPDATE trigger and replace the UPDATE statement with
Otherwise you'll get a mess of mutating table errors.
该错误告诉您将结果保存到变量中的查询返回多个结果。因此它不知道你想在变量中保存什么。
尝试运行以下命令:
我敢打赌它会给你多个结果,但它无法保存到 iva,idprod 中。
That error is telling you that a query that saves its result into a variable is returning more than one result. As such it doesn't know what you want to save in the variable.
Try running the following:
and I bet it will give you more than one result, which it can't save into
iva,idprod
.