Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Track Table History

Nel MarcusSep 25 2009 — edited Sep 30 2009
Hi,

I need to maintain history of TABLE_AA into TABLE_BB. Whenever a column is updated on TABLE_AA, the old record needs to be inserted into TABLE_BB (for history purpose). I am trying to achieve this using a trigger on the table AA but I am getting 2 records inserted everytime the trigger fires. Please help me here.


Here is the trigger code
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

CREATE OR REPLACE TRIGGER APPS.TABLEAA_TRIG
BEFORE UPDATE
ON APPS.TABLE_AA
REFERENCING NEW AS NEW OLD AS OLD


DECLARE
V_ERR_CODE NUMBER;
V_ERR_MSG VARCHAR2(255);

BEGIN

-- Insert into history table TABLE_BB --
INSERT INTO APPS.TABLE_BB
(COL1,
COL2,
COL3,
COL4,
COL5,
COL6,
COL7,
COL8,
COL9,
COL10)
VALUES
(:OLD.COL1,
:OLD.COL2,
:OLD.COL3,
:OLD.COL4,
:OLD.COL5,
:OLD.COL6,
:OLD.COL7,
:OLD.COL8,
:OLD.COL9,
:OLD.COL10);


EXCEPTION
WHEN OTHERS
THEN
V_ERR_CODE :=SQLCODE;
V_ERR_MSG := SQLERRM;
DBMS_OUTPUT.PUT_LINE(' Error : '||V_ERR_CODE||' has occurred. '||V_ERR_MSG);
END;

--------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 28 2009
Added on Sep 25 2009
3 comments
1,326 views