This discussion is archived
1 Reply Latest reply: Oct 5, 2012 8:23 AM by AdamMartin RSS

writing trigger for DML tracking on three table

shd Newbie
Currently Being Moderated
Hello,


I need help on how can i write a trigger for updating backup table on DML changes on source table.

I have source table named APP_SOURCE and backup table name APP_BACKUP with same data and structure.
On any DML on source table APP_SOURCE it corresponding backup table APP_BACKUP should also be updated with same number of record changes on any DML
(insert/update/delete) to maintain data consistency on both tables

For cross refernce all changed DML records on source table APP_SOURCE should be tracked and stored within third table APP_SOURCEDMLTRACK storing old value and new value data before and after dml changes on source table APP_SOURCE



source table create script:


CREATE TABLE APP_SOURCE
(
RCN_ID VARCHAR2(23 BYTE),
CRD_NUM VARCHAR2(23 BYTE),
TRN_TYP VARCHAR2(10 BYTE),
TRN_DTE DATE,
REF_NUM VARCHAR2(23 BYTE),
TRN_CRR VARCHAR2(3 BYTE),
TRN_AMT NUMBER(24,6),
BLL_CRR VARCHAR2(3 BYTE),
BLL_AMT NUMBER(16,2),
BSN_DTE DATE,
BRN_S VARCHAR2(10 BYTE),
ACC_NUM_S VARCHAR2(24 BYTE),
BRN_D VARCHAR2(10 BYTE),
ACC_NUM_D VARCHAR2(24 BYTE),
SRL_NUM VARCHAR2(12 BYTE),
DVI_TYP VARCHAR2(8 BYTE),
ORG_MSG_TYP VARCHAR2(6 BYTE),
ACQ_CDE VARCHAR2(15 BYTE),
ACQ_BIN VARCHAR2(11 BYTE),
REV VARCHAR2(1 BYTE),
DBCR_FLG VARCHAR2(1 BYTE),
ATM_FEE NUMBER(16,2),
ATM_ID VARCHAR2(16 BYTE),
INT_FEE NUMBER(16,2),
TRM_ID VARCHAR2(10 BYTE),
MCN_CDE VARCHAR2(40 BYTE),
MCN_INF VARCHAR2(40 BYTE),
PNT_RCN_ID NUMBER(12),
FGN_KEY VARCHAR2(23 BYTE),
ERR_CDE VARCHAR2(200 BYTE),
JNK VARCHAR2(50 BYTE),
CRD_USED VARCHAR2(10 BYTE),
RES_CDE VARCHAR2(3 BYTE),
REA_CDE VARCHAR2(4 BYTE),
PRC_CDE VARCHAR2(10 BYTE),
MCC VARCHAR2(4 BYTE),
APP_CDE VARCHAR2(8 BYTE),
ISS_INS_ID VARCHAR2(11 BYTE),
ACQ_INS_ID VARCHAR2(11 BYTE),
ACQ_NET_CDE VARCHAR2(20 BYTE),
ISS_NET_CDE VARCHAR2(20 BYTE),
INST_ID VARCHAR2(60 BYTE),
FIID1 VARCHAR2(20 BYTE),
FIID2 VARCHAR2(20 BYTE),
SWT_FLE VARCHAR2(50 BYTE),
VIS_FLE VARCHAR2(50 BYTE),
VIS_FLE_MCHDTE DATE,
VIS_FLE_EODDTE DATE,
VIS_FLE_RCNTYP NUMBER(2),
VIS_FLE_ACNTID VARCHAR2(35 BYTE),
MAS_FLE VARCHAR2(50 BYTE),
MAS_FLE_MCHDTE DATE,
MAS_FLE_EODDTE DATE,
MAS_FLE_RCNTYP NUMBER(2),
MAS_FLE_ACNTID VARCHAR2(35 BYTE),
TIE1_FLE VARCHAR2(50 BYTE),
TIE1_FLE_SRC VARCHAR2(50 BYTE),
TIE1_FLE_MCHDTE DATE,
TIE1_FLE_EODDTE DATE,
TIE1_FLE_RCNTYP NUMBER(2),
TIE1_FLE_ACNTID VARCHAR2(35 BYTE),
TIE2_FLE VARCHAR2(50 BYTE),
TIE2_FLE_SRC VARCHAR2(50 BYTE),
TIE2_FLE_MCHDTE DATE,
TIE2_FLE_EODDTE DATE,
TIE2_FLE_RCNTYP NUMBER(2),
TIE2_FLE_ACNTID VARCHAR2(35 BYTE),
TIE3_FLE VARCHAR2(50 BYTE),
TIE3_FLE_SRC VARCHAR2(50 BYTE),
TIE3_FLE_MCHDTE DATE,
TIE3_FLE_EODDTE DATE,
TIE3_FLE_RCNTYP NUMBER(2),
TIE3_FLE_ACNTID VARCHAR2(35 BYTE),
TIE4_FLE VARCHAR2(50 BYTE),
TIE4_FLE_SRC VARCHAR2(50 BYTE),
TIE4_FLE_MCHDTE DATE,
TIE4_FLE_EODDTE DATE,
TIE4_FLE_RCNTYP NUMBER(2),
TIE4_FLE_ACNTID VARCHAR2(35 BYTE),
TIE5_FLE VARCHAR2(50 BYTE),
TIE5_FLE_SRC VARCHAR2(50 BYTE),
TIE5_FLE_MCHDTE DATE,
TIE5_FLE_EODDTE DATE,
TIE5_FLE_RCNTYP NUMBER(2),
TIE5_FLE_ACNTID VARCHAR2(35 BYTE),
TIE6_FLE VARCHAR2(50 BYTE),
TIE6_FLE_SRC VARCHAR2(50 BYTE),
TIE6_FLE_MCHDTE DATE,
TIE6_FLE_EODDTE DATE,
TIE6_FLE_RCNTYP NUMBER(2),
TIE6_FLE_ACNTID VARCHAR2(35 BYTE),
EJ_FLE VARCHAR2(50 BYTE),
EJ_FLE_MCHDTE DATE,
EJ_FLE_EODDTE DATE,
EJ_FLE_RCNTYP NUMBER(2),
EJ_FLE_ACNTID VARCHAR2(35 BYTE),
BTH_FLE VARCHAR2(50 BYTE),
BTH_FLE_MCHDTE DATE,
BTH_FLE_EODDTE DATE,
BTH_FLE_RCNTYP NUMBER(2),
BTH_FLE_ACNTID VARCHAR2(35 BYTE),
BRN_ISS_FLE VARCHAR2(50 BYTE),
BRN_ISS_FLE_MCHDTE DATE,
BRN_ISS_FLE_EODDTE DATE,
BRN_ISS_FLE_RCNTYP NUMBER(2),
BRN_ISS_FLE_ACNTID VARCHAR2(35 BYTE),
BRN_ACQ_FLE VARCHAR2(50 BYTE),
BRN_ACQ_FLE_MCHDTE DATE,
BRN_ACQ_FLE_EODDTE DATE,
BRN_ACQ_FLE_RCNTYP NUMBER(2),
BRN_ACQ_FLE_ACNTID VARCHAR2(35 BYTE),
TRNACC_ID VARCHAR2(21 BYTE),
PRT_TRNACC_ID VARCHAR2(35 BYTE),
PROCESS_ID VARCHAR2(20 BYTE),
SWT_VCH1_NUM VARCHAR2(100 BYTE),
SWT_VCH2_NUM VARCHAR2(100 BYTE),
SWT_VCH3_NUM VARCHAR2(100 BYTE),
SWT_VCH4_NUM VARCHAR2(100 BYTE),
SWT_VCH5_NUM VARCHAR2(100 BYTE),
SWT_VCH1A_NUM VARCHAR2(100 BYTE),
SWT_VCH2A_NUM VARCHAR2(100 BYTE),
SWT_VCH3A_NUM VARCHAR2(100 BYTE),
SWT_VCH4A_NUM VARCHAR2(100 BYTE),
SWT_VCH5A_NUM VARCHAR2(100 BYTE),
SWT_VCH1B_NUM VARCHAR2(100 BYTE),
SWT_VCH2B_NUM VARCHAR2(100 BYTE),
SWT_VCH3B_NUM VARCHAR2(100 BYTE),
SWT_VCH4B_NUM VARCHAR2(100 BYTE),
SWT_VCH5B_NUM VARCHAR2(100 BYTE),
SWT_VCH1C_NUM VARCHAR2(100 BYTE),
SWT_VCH2C_NUM VARCHAR2(100 BYTE),
SWT_VCH3C_NUM VARCHAR2(100 BYTE),
SWT_VCH4C_NUM VARCHAR2(100 BYTE),
SWT_VCH5C_NUM VARCHAR2(100 BYTE),
SWT_VCH1D_NUM VARCHAR2(100 BYTE),
SWT_VCH2D_NUM VARCHAR2(100 BYTE),
SWT_VCH3D_NUM VARCHAR2(100 BYTE),
SWT_VCH4D_NUM VARCHAR2(100 BYTE),
SWT_VCH5D_NUM VARCHAR2(100 BYTE),
SWT_VCH1E_NUM VARCHAR2(100 BYTE),
SWT_VCH2E_NUM VARCHAR2(100 BYTE),
SWT_VCH3E_NUM VARCHAR2(100 BYTE),
SWT_VCH4E_NUM VARCHAR2(100 BYTE),
SWT_VCH5E_NUM VARCHAR2(100 BYTE),
SWT_VCH1F_NUM VARCHAR2(100 BYTE),
SWT_VCH2F_NUM VARCHAR2(100 BYTE),
SWT_VCH3F_NUM VARCHAR2(100 BYTE),
SWT_VCH4F_NUM VARCHAR2(100 BYTE),
SWT_VCH5F_NUM VARCHAR2(100 BYTE),
SWT_VCH1G_NUM VARCHAR2(100 BYTE),
SWT_VCH2G_NUM VARCHAR2(100 BYTE),
SWT_VCH3G_NUM VARCHAR2(100 BYTE),
SWT_VCH4G_NUM VARCHAR2(100 BYTE),
SWT_VCH5G_NUM VARCHAR2(100 BYTE),
SWT_VCH1H_NUM VARCHAR2(100 BYTE),
SWT_VCH2H_NUM VARCHAR2(100 BYTE),
SWT_VCH3H_NUM VARCHAR2(100 BYTE),
SWT_VCH4H_NUM VARCHAR2(100 BYTE),
SWT_VCH5H_NUM VARCHAR2(100 BYTE),
SWT_VCH1I_NUM VARCHAR2(100 BYTE),
SWT_VCH2I_NUM VARCHAR2(100 BYTE),
SWT_VCH3I_NUM VARCHAR2(100 BYTE),
SWT_VCH4I_NUM VARCHAR2(100 BYTE),
SWT_VCH5I_NUM VARCHAR2(100 BYTE),
VIS_VCH_NUM VARCHAR2(100 BYTE),
MAS_VCH_NUM VARCHAR2(100 BYTE),
TIE1_VCH_NUM VARCHAR2(100 BYTE),
TIE2_VCH_NUM VARCHAR2(100 BYTE),
TIE3_VCH_NUM VARCHAR2(100 BYTE),
TIE4_VCH_NUM VARCHAR2(100 BYTE),
TIE5_VCH_NUM VARCHAR2(100 BYTE),
TIE6_VCH_NUM VARCHAR2(100 BYTE),
EJ_VCH_NUM VARCHAR2(100 BYTE),
BTH_VCH_NUM VARCHAR2(100 BYTE),
BRN_ISS_VCH_NUM VARCHAR2(100 BYTE),
BRN_ACQ_VCH_NUM VARCHAR2(100 BYTE),
PAR_DTE DATE,
EOD_DTE1 DATE,
EOD_DTE2 DATE,
FILLER1 VARCHAR2(4000 BYTE),
FILLER2 VARCHAR2(4000 BYTE),
FILLER3 VARCHAR2(4000 BYTE),
BRM_LINKID1 VARCHAR2(20 BYTE),
BRM_LINKID2 VARCHAR2(20 BYTE),
BRN_ACQ_FLE_ORG VARCHAR2(50 BYTE),
CRM_TRACK_FLAG VARCHAR2(20 BYTE),
DIFF_AMT NUMBER(16,2),
IS_RCN NUMBER(1),
MCH_DTE DATE,
MIGRATION_FLAG VARCHAR2(50 BYTE),
NET_CDE VARCHAR2(20 BYTE),
TRACK_FLAG VARCHAR2(100 BYTE),
TRN_MM VARCHAR2(2 BYTE),
TRN_YY VARCHAR2(4 BYTE),
MOVE_FLAG VARCHAR2(15 BYTE),
PURGE_FLAG NUMBER(2),
REV_FLAG NUMBER(1),
TEMPVCH_LOCK_DTE DATE
)

Please provide me any refernce on web or document which i can implement or code on how to code the required trgger.


Regards,
Ganesh
  • 1. Re: writing trigger for DML tracking on three table
    AdamMartin Pro
    Currently Being Moderated
    Perhaps you should consider using Materialized View Replication.

    http://docs.oracle.com/cd/E11882_01/server.112/e10706/repoverview.htm#autoId9

    Instead of writing triggers, you put a materialized view log on your source table. Then you can turn your backup table into a materialized view that is based on the source table. When you perform a fast refresh of the backup table MV, it will read the MV log on the source table. Refreshes should take almost no time at all to process.

    If the data must be absolutely up-to-date at all times, you can use refresh on commit so that the MV is always in synch with the table. Normally I recommend against using refresh on commit, and instead recommend a short refresh interval.

    You can use triggers as you suggest, but it seems simpler to use something like MVs to create a shadow table.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points