I am trying to write a trigger that when the user_info.ui_lastlogin is updated then I want the data sent to another table. The point of this is that the user_info table is only keeping up with the last time a person logged in and their user name. We need every time a person logs in and their user name. So we thought if we captured data before the data changed again then this would give us our requirement. But I suck at triggers and this one is giving me a strange error ORA-04091 (mutating table) AND ORA-06512 AND ORA-04088. Could someone please help me.
Here is the code so far:
CREATE OR REPLACE TRIGGER MCEMGR.ECAM_TRIGGER
AFTER INSERT
ON MCEMGR.USER_INFO
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
Insert into tbl_ecam_user
(ecam_user, ecam_dte)
select ui_user, ui_last_login
from User_info
where
ui_last_login = (select max(ui_last_login) from user_info
WHERE ui_last_login IS NOT NULL
AND TO_CHAR(ui_last_login,'DD-MON-YYYY') = 'TRUNC(SYSDATE)'
);
end ecam_trigger;
Here is the code so far:
CREATE OR REPLACE TRIGGER MCEMGR.ECAM_TRIGGER
AFTER INSERT
ON MCEMGR.USER_INFO
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
Insert into tbl_ecam_user
(ecam_user, ecam_dte)
select ui_user, ui_last_login
from User_info
where
ui_last_login = (select max(ui_last_login) from user_info
WHERE ui_last_login IS NOT NULL
AND TO_CHAR(ui_last_login,'DD-MON-YYYY') = 'TRUNC(SYSDATE)'
);
end ecam_trigger;