--Author: Venkata Potluri
--Date: July 17, 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, 'Drop Index S_LOY_TXN_150710A', SYSDATE FROM DUAL;

   COMMIT;

   BEGIN
      EXECUTE IMMEDIATE 'DROP INDEX SIEBEL.S_LOY_TXN_150710A';
   EXCEPTION
      WHEN OTHERS
      THEN
         DBMS_OUTPUT.PUT_LINE (
            'Index SIEBEL.S_LOY_TXN_150710A doesn''t exist.');
   END;

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

   COMMIT;
END;
/

QUIT