:NEW cannot be used in After Delete Trigger ?
RakinFeb 17 2010 — edited Feb 17 2010Hi,
Is there any way to get the :NW.value in the After delete trigger for each row. My requirement is audit log of the end user DML operations along with user Name (HERE THE USER IS NOT THE ORACLE USER, BECAUSE OF THE LARGE NUMBER OF END USERS WE ARE MAINTAINING ONE TABLE TO CREATE USER NAME & PASSWORD, WHEN THE USER LOGIN TO ORACLE FORM SCREEN, ASSIGN THE USER NAME TO GLOBAL VARIABLE) & Action Date.
Here is my code for trigger - It is working fine with INSER & UPDATE but for DELETE User is NULL
CREATE OR REPLACE TRIGGER Tgr_stud_det
AFTER INSERT OR UPDATE OR DELETE ON student_details
FOR EACH ROW
DECLARE
BEGIN
IF Inserting THEN
-------------INSERT VALUE---------------
INSERT INTO Log_student_details
(Seq,
App_User,
Action,
Action_Date,
stud_name,
stud_age,
stud_sex)
VALUES
(stud_sequence.NEXTVAL,
:NEW.App_User,
'INSERT',
SYSDATE,
:NEW.stud_name,
:NEW.stud_age,
:NEW.stud_sex);
-------------DELETE VALUE---------------
ELSIF Deleting THEN
INSERT INTO Log_student_details
(Seq,
App_User,
Action,
Action_Date,
Comment_Up,
stud_name,
stud_age,
stud_sex)
VALUES
(stud_sequence.NEXTVAL,
:OLD.App_User,
'DELETE',
SYSDATE,
NULL,
:OLD.stud_name,
:OLD.stud_age,
:OLD.stud_sex);
ELSIF Updating THEN
-------------UPDATE VALUE---------------
INSERT INTO Log_student_details
(Seq,
App_User,
Action,
Action_Date,
Comment_Up,
stud_name,
stud_age,
stud_sex)
VALUES
(stud_sequence.NEXTVAL,
:NEW.App_User,
'UPDATE',
SYSDATE,
'NEW VALUE',
:NEW.stud_name,
:NEW.stud_age,
:NEW.stud_sex);
INSERT INTO Log_student_details
(Seq,
App_User,
Action,
Action_Date,
Comment_Up,
stud_name,
stud_age,
stud_sex)
VALUES
(stud_sequence.CURRVAL,
:NEW.App_User,
'UPDATE',
SYSDATE,
'OLD VALUE',
:OLD.stud_name,
:OLD.stud_age,
:OLD.stud_sex);
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END Tgr_stud_det;
Thanks in advance.