简体   繁体   中英

how to solve the error 'ORA-04091: table WKSP_APEXHENRY.TEST1 is mutating, trigger/function may not see it' on Oracle APEX

I create a trigger with oracle apex. And I created an App with oracle apex. The code is as follows:

CREATE TABLE test1
(
  test1data1 INT NOT NULL,
  test1data2 INT NOT NULL,
  test1key VARCHAR(20) NOT NULL,
  PRIMARY KEY (test1key)
);
insert into test
values(10,10,001);

CREATE OR REPLACE EDITIONABLE TRIGGER  "TEST1_T1" 
AFTER
update on "TEST1"
for each row
begin
update test1
set test1data1 = :new.test1data2-:old.test1data2;
end;
/
ALTER TRIGGER  "TEST1_T1" ENABLE
/

I use App Builder on APEX to create a website page. When I change the value of 'test1data2', it shows that

ORA-04091: table WKSP_APEXHENRY.TEST1 is mutating, trigger/function may not see it'.

How to solve this problem? Thank you.

[[ screenshot of problem ]( https://i.stack.imgur.com/GV2Ov.png )]( https://i.stack.imgur.com/5Oy4g.png )

I hope the error can disappear and the trigger can run smoothly.

You are not permitted in a trigger to change the table the triggering statement is modifying. That's what it means by mutating.

Instead, change it to a BEFORE update trigger and inside just assign:new.test1data1. No update is required.

eg

CREATE OR REPLACE EDITIONABLE TRIGGER "TEST1_T1" BEFORE update on "TEST1" 
for each row 
begin 
  :new.test1data1 := :new.test1data2;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM