--Author: Venkata Potluri
--Date: Oct 20, 2015

DECLARE
   TYPE T_ROW_ID IS TABLE OF SIEBEL_PURGE.TEMP_TXN_10212015.ROW_ID%TYPE;

   TYPE T_TOTAL_POINTS IS TABLE OF SIEBEL_PURGE.TEMP_TXN_10212015.TOTAL_POINTS%TYPE;

   ARR_ROW_ID      T_ROW_ID;
   ARR_TOTAL_POINTS   T_TOTAL_POINTS;

   CURSOR C1
   IS
        SELECT TXN_ID, SUM (ACCRUALED_VALUE)
          FROM SIEBEL.S_LOY_ACRL_ITM A
               INNER JOIN SIEBEL_PURGE.TEMP_TXN_10212015 T ON T.ROW_ID = A.TXN_ID
      GROUP BY TXN_ID;
BEGIN
   OPEN C1;

   LOOP
      FETCH C1 BULK COLLECT INTO ARR_ROW_ID, ARR_TOTAL_POINTS LIMIT 50;

      FORALL ROW IN ARR_ROW_ID.FIRST .. ARR_ROW_ID.LAST
         UPDATE SIEBEL_PURGE.TEMP_TXN_10212015
            SET TOTAL_POINTS = ARR_TOTAL_POINTS (ROW)
          WHERE ROW_ID = ARR_ROW_ID (ROW);

      COMMIT;

      EXIT WHEN C1%NOTFOUND;
   END LOOP;

   CLOSE C1;
END;
/

QUIT