--Author: Venkata Potluri
--Date: April 08, 2015

--I think using the parallel hint on the P table, but I don't like the ROWID lookup on the S_LOY_MEMBER table (4GB), so if this is not fast enough - we can try adding a parallel full on S_LOY_MEMBER

DECLARE
   LOG_ROW_ID   NUMBER := 0;
   ROW_COUNT    NUMBER := 0;
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, 'Update PURGE_MEM_REDEEMABLE Part-2/5', SYSDATE
        FROM DUAL;

   COMMIT;

   UPDATE (SELECT /*+ parallel(P,5) full(P) */
                 P.MEMBER_ID P_MI,
                  P.MEM_NUM P_MN,
                  P.MEM_AVAIL_POINTS P_AP,
                  M.POINT_TYPE_E_VAL M_AP,
                  M.MEM_NUM M_MN,
                  M.ROW_ID M_RI
             FROM SIEBEL_PURGE.PURGE_MEM_REDEEMABLE P
                  INNER JOIN SIEBEL.S_LOY_MEMBER M ON P.MEMBER_ID = M.ROW_ID
            WHERE P.UPDATED_FLG = 'Y')
      SET P_AP = M_AP, P_MN = M_MN
    WHERE P_MI = M_RI;

   ROW_COUNT := SQL%ROWCOUNT;
   COMMIT;

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

   COMMIT;
END;
/

QUIT