--Author: Venkata Potluri
--Date: Aug 12, 2015

DECLARE
   TYPE T_FROM_MEM_ID IS TABLE OF SIEBEL_PURGE.MEM_MERGE.FROM_MEM_ID%TYPE;

   TYPE T_TO_MEM_ID IS TABLE OF SIEBEL_PURGE.MEM_MERGE.TO_MEM_ID%TYPE;

   ARR_FROM_MEM_ID   T_FROM_MEM_ID;
   ARR_TO_MEM_ID     T_TO_MEM_ID;

   LOG_ROW_ID        NUMBER := 0;
   LOG_ROW_ID_2      NUMBER := 0;
   LOG_ROW_ID_3      NUMBER := 0;
   LOG_ROW_ID_4      NUMBER := 0;
   LOG_ROW_ID_5      NUMBER := 0;
   ROW_COUNT         NUMBER := 0;

   V_FROM_PI         VARCHAR2 (100 CHAR);
   V_TO_PI           VARCHAR2 (100 CHAR);

   T1_U_PMT          NUMBER := 0;
   T1_D_ELT          NUMBER := 0;
   T1_D_ELA          NUMBER := 0;
   T1_D_ECD          NUMBER := 0;
   T1_D_PMT          NUMBER := 0;
   T1_D_PMR          NUMBER := 0;
   T1_D_PMI          NUMBER := 0;
   T1_U_PISLRI       NUMBER := 0;
   T1_U_PISLAI       NUMBER := 0;
   T1_U_PISCX        NUMBER := 0;
   T1_U_RR1          NUMBER := 0;
   T1_U_RR2          NUMBER := 0;

   T2_U_PMT1         NUMBER := 0;
   T2_U_PMT2         NUMBER := 0;
   T2_U_PMR          NUMBER := 0;
   T2_U_PMI          NUMBER := 0;
   T2_U_PISLRI       NUMBER := 0;
   T2_U_PISLAI       NUMBER := 0;
   T2_U_PISCX        NUMBER := 0;
   T2_U_RR1          NUMBER := 0;
   T2_U_RR2          NUMBER := 0;
   T2_U_ECD          NUMBER := 0;

   CURSOR C1
   IS
      SELECT DISTINCT M.ROW_ID FROM_MEM_ID, TM.MEMBER_ID TO_MEM_ID
        FROM SIEBEL.S_LOY_TXN$M TM
             INNER JOIN SIEBEL.S_LOY_MEMBER M
                ON TM.X_ORIG_MBR_NBR = M.MEM_NUM
       WHERE M.ROW_ID <> TM.MEMBER_ID;
BEGIN
   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, START_TIME)
      SELECT LOG_ROW_ID, 'Sync Merged Members'' details', SYSDATE FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, START_TIME)
      SELECT LOG_ROW_ID + 1, 'Populate MEM_MERGE', SYSDATE
        FROM DUAL;

   COMMIT;

   EXECUTE IMMEDIATE 'TRUNCATE TABLE SIEBEL_PURGE.MEM_MERGE';

   OPEN C1;

   LOOP
      FETCH C1 BULK COLLECT INTO ARR_FROM_MEM_ID, ARR_TO_MEM_ID LIMIT 1000;
	  --FETCH C1 BULK COLLECT INTO ARR_FROM_MEM_ID, ARR_TO_MEM_ID LIMIT 50;

      FORALL ROW IN ARR_FROM_MEM_ID.FIRST .. ARR_FROM_MEM_ID.LAST
         INSERT INTO SIEBEL_PURGE.MEM_MERGE (FROM_MEM_ID, TO_MEM_ID)
              VALUES (ARR_FROM_MEM_ID (ROW), ARR_TO_MEM_ID (ROW));

      ROW_COUNT := ROW_COUNT + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.PURGE_LOG
         SET PROCESSED_ROWS = ROW_COUNT
       WHERE ROW_ID = LOG_ROW_ID + 1;

      COMMIT;

      EXIT WHEN C1%NOTFOUND;
   END LOOP;

   CLOSE C1;

   UPDATE SIEBEL_PURGE.PURGE_LOG
      SET END_TIME = SYSDATE, PROCESSED_ROWS = ROW_COUNT
    WHERE ROW_ID = LOG_ROW_ID + 1;

   COMMIT;

   -----------------------------------------------------------------------
   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID_2
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, START_TIME)
      SELECT LOG_ROW_ID_2, 'Find New Merges', SYSDATE FROM DUAL;

   COMMIT;

   UPDATE (SELECT NEW_MERGE, FROM_MEM_ID, MEMBER_ID
             FROM SIEBEL_PURGE.MEM_MERGE MM
                  INNER JOIN SIEBEL_PURGE.PURGE_MEM_TXN MT
                     ON MM.FROM_MEM_ID = MT.MEMBER_ID)
      SET NEW_MERGE = 'Y'
    WHERE FROM_MEM_ID = MEMBER_ID;

   ROW_COUNT := SQL%ROWCOUNT;

   UPDATE SIEBEL_PURGE.PURGE_LOG
      SET END_TIME = SYSDATE, PROCESSED_ROWS = ROW_COUNT
    WHERE ROW_ID = LOG_ROW_ID_2;

   COMMIT;

   -----------------------------------------------------------------------
   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID_3
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, START_TIME)
      SELECT LOG_ROW_ID_3,
             'Find if ''To Member'' exists in PURGE tables',
             SYSDATE
        FROM DUAL;

   COMMIT;

   UPDATE (SELECT TO_MEM_EXISTS, TO_MEM_ID, MEMBER_ID
             FROM SIEBEL_PURGE.MEM_MERGE MM
                  INNER JOIN SIEBEL_PURGE.PURGE_MEM_TXN MT
                     ON MM.TO_MEM_ID = MT.MEMBER_ID)
      SET TO_MEM_EXISTS = 'Y'
    WHERE TO_MEM_ID = MEMBER_ID;

   ROW_COUNT := SQL%ROWCOUNT;

   UPDATE SIEBEL_PURGE.PURGE_LOG
      SET END_TIME = SYSDATE, PROCESSED_ROWS = ROW_COUNT
    WHERE ROW_ID = LOG_ROW_ID_3;

   COMMIT;

   ------------------------------------------------------------------
   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID_4
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, START_TIME)
      SELECT LOG_ROW_ID_4, 'Updating Type-1 Merges', SYSDATE FROM DUAL;

   COMMIT;

   FOR T1 IN (SELECT FROM_MEM_ID, TO_MEM_ID
                FROM SIEBEL_PURGE.MEM_MERGE
               WHERE NEW_MERGE = 'Y' AND TO_MEM_EXISTS = 'Y')
   LOOP
      UPDATE SIEBEL_PURGE.PURGE_MEM_TXN
         SET UPDATED_FLG = 'T'
       WHERE MEMBER_ID = T1.TO_MEM_ID;

      T1_U_PMT := T1_U_PMT + SQL%ROWCOUNT;

      DELETE /*+ index(EIM_LOY_TXN,EIM_LOY_TXN_150819C) */
            FROM  SIEBEL.EIM_LOY_TXN
            WHERE TXN_NUM = (SELECT TXN_NUM
                               FROM SIEBEL_PURGE.PURGE_MEM_TXN
                              WHERE MEMBER_ID = T1.FROM_MEM_ID);

      T1_D_ELT := T1_D_ELT + SQL%ROWCOUNT;

      DELETE /*+ index(EIM_LOY_ACRLIT,EIM_LOY_ACRLIT_150819D) */
            FROM  SIEBEL.EIM_LOY_ACRLIT
            WHERE ITEM_NUM = (SELECT ITEM_NUM
                                FROM SIEBEL_PURGE.PURGE_MEM_TXN
                               WHERE MEMBER_ID = T1.FROM_MEM_ID);

      T1_D_ELA := T1_D_ELA + SQL%ROWCOUNT;

      DELETE /*+ index(EIM_CON_DTL,EIM_CON_DTL_150826A) */
            FROM  SIEBEL.EIM_CON_DTL
            WHERE CON_PERSON_UID = (SELECT PERSON_UID
                                      FROM SIEBEL_PURGE.PURGE_MEM_TXN
                                     WHERE MEMBER_ID = T1.FROM_MEM_ID);

      T1_D_ECD := T1_D_ECD + SQL%ROWCOUNT;

      DELETE FROM SIEBEL_PURGE.PURGE_MEM_TXN
            WHERE MEMBER_ID = T1.FROM_MEM_ID;

      T1_D_PMT := T1_D_PMT + SQL%ROWCOUNT;

      DELETE FROM SIEBEL_PURGE.PURGE_MEM_REDEEMABLE
            WHERE MEMBER_ID = T1.FROM_MEM_ID;

      T1_D_PMR := T1_D_PMR + SQL%ROWCOUNT;

      DELETE FROM SIEBEL_PURGE.PURGE_MEM_INFO
            WHERE MEMBER_ID = T1.FROM_MEM_ID;

      T1_D_PMI := T1_D_PMI + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM
         SET MEM_ID = T1.TO_MEM_ID
       WHERE MEM_ID = T1.FROM_MEM_ID;

      T1_U_PISLRI := T1_U_PISLRI + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.P_INT_S_LOY_ATTR_ITM
         SET MEM_ID = T1.TO_MEM_ID
       WHERE MEM_ID = T1.FROM_MEM_ID;

      T1_U_PISLAI := T1_U_PISLAI + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.P_INT_S_CONTACT_XM
         SET MEM_ID = T1.TO_MEM_ID
       WHERE MEM_ID = T1.FROM_MEM_ID;

      T1_U_PISCX := T1_U_PISCX + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.RDM_REPORT
         SET MEM_ID = T1.TO_MEM_ID
       WHERE MEM_ID = T1.FROM_MEM_ID;

      T1_U_RR1 := T1_U_RR1 + SQL%ROWCOUNT;
      COMMIT;

      UPDATE (SELECT M.ROW_ID M_MEM_ID,
                     M.MEM_NUM M_MEM_NUM,
                     M.STATUS_CD M_MEM_STATUS,
                     TIER.NAME M_TIER_NAME,
                     RR.MEM_ID RR_MEM_ID,
                     RR.MEM_NUM RR_MEM_NUM,
                     RR.MEM_STATUS RR_MEM_STATUS,
                     RR.TIER_NAME RR_TIER_NAME
                FROM SIEBEL_PURGE.RDM_REPORT RR
                     INNER JOIN SIEBEL.S_LOY_MEMBER M
                        ON M.ROW_ID = RR.MEM_ID AND M.ROW_ID = T1.TO_MEM_ID
                     INNER JOIN SIEBEL.S_LOY_TIER TIER
                        ON M.PR_DOM_TIER_ID = TIER.ROW_ID)
         SET RR_MEM_NUM = M_MEM_NUM,
             RR_MEM_STATUS = M_MEM_STATUS,
             RR_TIER_NAME = M_TIER_NAME
       WHERE RR_MEM_ID = M_MEM_ID;

      T1_U_RR2 := T1_U_RR2 + SQL%ROWCOUNT;
      COMMIT;
   END LOOP;

   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID_2
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2, 'T1 Update PURGE_MEM_TXN', T1_U_PMT FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 1, 'T1 Delete EIM_LOY_TXN', T1_D_ELT
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 2, 'T1 Delete EIM_LOY_ACRLIT', T1_D_ELA
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 3, 'T1 Delete EIM_CON_DTL', T1_D_ECD
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 4, 'T1 Delete PURGE_MEM_TXN', T1_D_PMT
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 5, 'T1 Delete PURGE_MEM_REDEEMABLE', T1_D_PMR
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 6, 'T1 Delete PURGE_MEM_INFO', T1_D_PMI
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 7, 'T1 Update P_INT_S_LOY_RDM_INT', T1_U_PISLRI
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 8, 'T1 Update P_INT_S_LOY_ATTR_ITM', T1_U_PISLAI
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 9, 'T1 Update P_INT_S_CONTACT_XM', T1_U_PISCX
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 10, 'T1 Update_1 RDM_REPORT', T1_U_RR1
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_2 + 11, 'T1 Update_2 RDM_REPORT', T1_U_RR2
        FROM DUAL;

   COMMIT;

   UPDATE SIEBEL_PURGE.PURGE_LOG
      SET END_TIME = SYSDATE
    WHERE ROW_ID = LOG_ROW_ID_4;

   COMMIT;

   ------------------------------------------------------------------
   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID_5
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, START_TIME)
      SELECT LOG_ROW_ID_5, 'Updating Type-2 Merges', SYSDATE FROM DUAL;

   COMMIT;

   FOR T2 IN (SELECT FROM_MEM_ID, TO_MEM_ID
                FROM SIEBEL_PURGE.MEM_MERGE
               WHERE NEW_MERGE = 'Y' AND TO_MEM_EXISTS = 'N')
   LOOP
      SELECT PERSON_UID
        INTO V_FROM_PI
        FROM SIEBEL_PURGE.PURGE_MEM_TXN
       WHERE MEMBER_ID = T2.FROM_MEM_ID;

      UPDATE SIEBEL_PURGE.PURGE_MEM_TXN
         SET MEMBER_ID = T2.TO_MEM_ID
       WHERE MEMBER_ID = T2.FROM_MEM_ID;

      T2_U_PMT1 := T2_U_PMT1 + SQL%ROWCOUNT;
      COMMIT;

      UPDATE (SELECT P.MEMBER_ID P_MI,
                     P.MEM_NUM P_MN,
                     P.PERSON_UID P_PCI,
                     P.UPDATED_FLG,
                     M.MEM_NUM M_MN,
                     C.PERSON_UID M_PCI,
                     M.ROW_ID M_RI
                FROM SIEBEL_PURGE.PURGE_MEM_TXN P
                     INNER JOIN SIEBEL.S_LOY_MEMBER M
                        ON P.MEMBER_ID = M.ROW_ID AND M.ROW_ID = T2.TO_MEM_ID
                     INNER JOIN SIEBEL.S_CONTACT C ON C.ROW_ID = M.PR_CON_ID)
         SET P_MN = M_MN, P_PCI = M_PCI, UPDATED_FLG = 'T'
       WHERE P_MI = M_RI;

      T2_U_PMT2 := T2_U_PMT2 + SQL%ROWCOUNT;
      COMMIT;

      UPDATE SIEBEL_PURGE.PURGE_MEM_REDEEMABLE
         SET MEMBER_ID = T2.TO_MEM_ID
       WHERE MEMBER_ID = T2.FROM_MEM_ID;

      T2_U_PMR := T2_U_PMR + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.PURGE_MEM_INFO
         SET MEMBER_ID = T2.TO_MEM_ID
       WHERE MEMBER_ID = T2.FROM_MEM_ID;

      T2_U_PMI := T2_U_PMI + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM
         SET MEM_ID = T2.TO_MEM_ID
       WHERE MEM_ID = T2.FROM_MEM_ID;

      T2_U_PISLRI := T2_U_PISLRI + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.P_INT_S_LOY_ATTR_ITM
         SET MEM_ID = T2.TO_MEM_ID
       WHERE MEM_ID = T2.FROM_MEM_ID;

      T2_U_PISLAI := T2_U_PISLAI + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.P_INT_S_CONTACT_XM
         SET MEM_ID = T2.TO_MEM_ID
       WHERE MEM_ID = T2.FROM_MEM_ID;

      T2_U_PISCX := T2_U_PISCX + SQL%ROWCOUNT;

      UPDATE SIEBEL_PURGE.RDM_REPORT
         SET MEM_ID = T2.TO_MEM_ID
       WHERE MEM_ID = T2.FROM_MEM_ID;

      T2_U_RR1 := T2_U_RR1 + SQL%ROWCOUNT;
      COMMIT;

      UPDATE (SELECT M.ROW_ID M_MEM_ID,
                     M.MEM_NUM M_MEM_NUM,
                     M.STATUS_CD M_MEM_STATUS,
                     TIER.NAME M_TIER_NAME,
                     RR.MEM_ID RR_MEM_ID,
                     RR.MEM_NUM RR_MEM_NUM,
                     RR.MEM_STATUS RR_MEM_STATUS,
                     RR.TIER_NAME RR_TIER_NAME
                FROM SIEBEL_PURGE.RDM_REPORT RR
                     INNER JOIN SIEBEL.S_LOY_MEMBER M
                        ON M.ROW_ID = RR.MEM_ID AND M.ROW_ID = T2.TO_MEM_ID
                     INNER JOIN SIEBEL.S_LOY_TIER TIER
                        ON M.PR_DOM_TIER_ID = TIER.ROW_ID)
         SET RR_MEM_NUM = M_MEM_NUM,
             RR_MEM_STATUS = M_MEM_STATUS,
             RR_TIER_NAME = M_TIER_NAME
       WHERE RR_MEM_ID = M_MEM_ID;

      T2_U_RR2 := T2_U_RR2 + SQL%ROWCOUNT;
      COMMIT;

      SELECT PERSON_UID
        INTO V_TO_PI
        FROM SIEBEL_PURGE.PURGE_MEM_TXN
       WHERE MEMBER_ID = T2.TO_MEM_ID;

      UPDATE SIEBEL.EIM_CON_DTL
         SET CON_PERSON_UID = V_TO_PI, PARTY_UID = V_TO_PI
       WHERE CON_PERSON_UID = V_FROM_PI;

      T2_U_ECD := T2_U_ECD + SQL%ROWCOUNT;
      COMMIT;
   END LOOP;

   SELECT CASE WHEN MAX (ROW_ID) IS NOT NULL THEN MAX (ROW_ID) + 1 ELSE 1 END
     INTO LOG_ROW_ID_3
     FROM SIEBEL_PURGE.PURGE_LOG;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3, 'T2 Update_1 PURGE_MEM_TXN', T2_U_PMT1 FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 1, 'T2 Update_2 PURGE_MEM_TXN', T2_U_PMT2
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 2, 'T2 Update PURGE_MEM_REDEEMABLE', T2_U_PMR
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 3, 'T2 Update PURGE_MEM_INFO', T2_U_PMI
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 4, 'T2 Update P_INT_S_LOY_RDM_ITM', T2_U_PISLRI
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 5, 'T2 Update P_INT_S_LOY_ATTR_ITM', T2_U_PISLAI
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 6, 'T2 Update P_INT_S_CONTACT_XM', T2_U_PISCX
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 7, 'T2 Update_1 RDM_REPORT', T2_U_RR1
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 8, 'T2 Update_2 RDM_REPORT', T2_U_RR2
        FROM DUAL;

   COMMIT;

   INSERT INTO SIEBEL_PURGE.PURGE_LOG (ROW_ID, PROCESS_NAME, PROCESSED_ROWS)
      SELECT LOG_ROW_ID_3 + 9, 'T2 Update EIM_CON_DTL', T2_U_ECD
        FROM DUAL;

   COMMIT;

   UPDATE SIEBEL_PURGE.PURGE_LOG
      SET END_TIME = SYSDATE
    WHERE ROW_ID = LOG_ROW_ID_5;

   COMMIT;

   ------------------------------------------------------------------
   UPDATE SIEBEL_PURGE.PURGE_LOG
      SET END_TIME = SYSDATE
    WHERE ROW_ID = LOG_ROW_ID;

   COMMIT;
END;
/

QUIT