gpt4 book ai didi

oracle - ORA-04084 : cannot change NEW values for this trigger type

转载 作者:行者123 更新时间:2023-12-01 22:03:47 29 4
gpt4 key购买 nike

我正在尝试打开 pl/sql 触发器,该触发器在故事更改时计算表中某些单元格的总数。这是代码:

  ALTER session SET nls_date_format='dd/mm/yyyy';

CREATE OR REPLACE TRIGGER TOTAL
AFTER UPDATE OR INSERT ON ORDER_ITEMS
FOR EACH ROW
DECLARE
temp NUMBER;
today DATE;
BEGIN
temp:=(:NEW.item_price-:NEW.discount_amount)*:NEW.quantity;
today := CURRENT_DATE;
:NEW.TOTAL := temp;
dbms_output.put_line('Updated on:' ||today || ' item number: ' ||:NEW.item_id|| 'order number:' ||:NEW.order_id|| 'total: ' ||:NEW.total);
END;
/
show errors

insert into order_items (ITEM_ID, ORDER_ID, PRODUCT_ID, ITEM_PRICE, discount_amount, QUANTITY)
VALUES (13, 7, 3, 553, 209, 2);

我收到此错误:

  1. 00000 - "cannot change NEW values for this trigger type" *Cause: New trigger variables can only be changed in before row insert or update triggers. *Action: Change the trigger type or remove the variable reference. No Errors. 1 rows inserted Updated on:06/01/2016 item number: 13order number:7total:

据我所知,问题是在触发器执行期间更新表,这是由对同一个表的更新引起的。

最佳答案

根据评论中的要求,我将评论作为答案。

您的问题是因为您尝试在值保留后更改值,请尝试将触发器更改为BEFORE,如下所示:

CREATE OR REPLACE TRIGGER TOTAL
BEFORE UPDATE OR INSERT ON ORDER_ITEMS
FOR EACH ROW
DECLARE
temp NUMBER;
today DATE;
BEGIN
temp:=(:NEW.item_price-:NEW.discount_amount)*:NEW.quantity;
today := CURRENT_DATE;
:NEW.TOTAL := temp;
dbms_output.put_line('Updated on:' || today || ' item number: '
|| :NEW.item_id || 'order number:' || :NEW.order_id
|| 'total: ' ||:NEW.total);
END;
/

关于oracle - ORA-04084 : cannot change NEW values for this trigger type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34638202/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com