--Author: Venkata Potluri
--Date: July 16, 2015

DECLARE
   LOG_ROW_ID   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, 'Build Index S_LOY_TXN_150710A', SYSDATE FROM DUAL;

   COMMIT;

   EXECUTE IMMEDIATE
      'CREATE INDEX SIEBEL.S_LOY_TXN_150710A
   ON SIEBEL.S_LOY_TXN (ROW_ID, X_PURGE_FLG, MEMBER_ID)
   TABLESPACE SIEBEL_INDEX
   PARALLEL 6';

   EXECUTE IMMEDIATE 'Alter index SIEBEL.S_LOY_TXN_150710A noparallel';

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

   COMMIT;
END;
/

QUIT