Home » SQL & PL/SQL » SQL & PL/SQL » Trigger for delete please help!!
Trigger for delete please help!! [message #20615] Fri, 07 June 2002 04:25 Go to next message
JOHN
Messages: 182
Registered: April 1998
Senior Member
I would like to create a trigger that writes the deleted data from table <orders> to the table <log> and writes also the SYSDATE, OSUSER and MACHINE that deleted this data.

Can anybody help?
Re: Trigger for delete please help!! [message #20617 is a reply to message #20615] Fri, 07 June 2002 07:19 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
hope this will help you
SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> select * from dept_deleted;

no rows selected

SQL> get tr8
  1   CREATE OR REPLACE TRIGGER audit_dept AFTER DELETE  ON dept
  2          FOR EACH ROW
  3   DECLARE
  4     PRAGMA AUTONOMOUS_TRANSACTION;
  5   BEGIN
  6        INSERT INTO dept_deleted
  7        VALUES( :old.deptno, :old.dname, :old.loc, sysdate,user ,
  8                sys_context('userenv','ip_address'));
  9        COMMIT;
 10*  END;
SQL> /

Trigger created.

SQL> delete from dept;

4 rows deleted.

SQL> select * from dept_deleted;

    DEPTNO DNAME          LOC           DATED     OUSER                          MACHINE
---------- -------------- ------------- --------- ------------------------------ -------------------
        10 ACCOUNTING     NEW YORK      07-JUN-02 MAG                            192.168.1.104
        20 RESEARCH       DALLAS        07-JUN-02 MAG                            192.168.1.104
        30 SALES          CHICAGO       07-JUN-02 MAG                            192.168.1.104
        40 OPERATIONS     BOSTON        07-JUN-02 MAG                            192.168.1.104
Previous Topic: Getting record set back from stored proc
Next Topic: Re: What is wrong with my logic?
Goto Forum:
  


Current Time: Thu Apr 25 02:51:06 CDT 2024