I am trying to create a trigger that copies the value from one column ("notubes" into another one ("notubesleft") of the same table when a new row is added. The trigger is compiled correctly but when I insert a new row, it throws an error.
My trigger is:
create or replace TRIGGER NOTUBESLEFT_INSERT_TRIGGER
AFTER INSERT ON SAMPLES FOR EACH ROW BEGIN
update samples
set notubesleft = (select notubes from samples where sampleid = :new.sampleid);
END;
When I try to commit a new row I get the error:
One error saving changes to table "APEX_WS_PROMETHEUS"."SAMPLES":
Row 10: ORA-04091: table APEX_WS_PROMETHEUS.SAMPLES is mutating, trigger/function may not see it
ORA-06512: at "APEX_WS_PROMETHEUS.NOTUBESLEFT_INSERT_TRIGGER", line 2 ORA-04088: error during execution of trigger 'APEX_WS_PROMETHEUS.NOTUBESLEFT_INSERT_TRIGGER'
ORA-06512: at line 1
I am asking a new question because I could find solutions on how to structure the PL/SQL code of the trigger, but I can't figure out why it does not work.
Thanks.