--Author: Venkata Potluri
--Date: June 11, 2015

--8.00 mins in New QA

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 TEMP_TXN_MEM_U1', SYSDATE FROM DUAL;

   COMMIT;

   EXECUTE IMMEDIATE
      'CREATE UNIQUE INDEX SIEBEL_PURGE.TEMP_TXN_MEM_U1
   ON SIEBEL_PURGE.TEMP_TXN_MEM (TXN_ID, T_MEM_ID) PARALLEL 12';

   EXECUTE IMMEDIATE 'ALTER INDEX SIEBEL_PURGE.TEMP_TXN_MEM_U1 NOPARALLEL';

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

   COMMIT;
END;
/

QUIT