I want to create something like an audit table.
And I want to insert to this table new values from table CLIENT with join this new values with values from table CODEWORD. I try to use trigger on insert to my table CLIENT:
TRIGGER CLIENT_CODEWORD_INSERT
AFTER
INSERT ON TEST2.CLIENT
FOR EACH ROW
DECLARE code_word varchar2(100);
BEGIN
SELECT t2.VAL INTO code_word FROM test2.CODEWORD t2 LEFT JOIN test2.CLIENT t1 ON T2.CLIENTID = t1.ID WHERE t1.Id = :NEW.ID;
INSERT INTO CLIENT_UPDATE (
ID
,NAME
,PHONE
,CODEWORD
)
VALUES (
:NEW.ID
,SUBSTR (:NEW.NAME, 2,7)
,CONCat(:NEW.PHONE,'!')
, code_word
);
END;
But I received an error on attempts to insert values into table CLIENT:
SQL Error [4091] [42000]: ORA-04091: table TEST2.CLIENT is mutating, , trigger/function may not see it
ORA-06512: on "TEST2.CLIENT_CODEWORD_INSERT", line 3
No need for join in
SELECT
statement; just use:new.id
.