--Author: Venkata Potluri
--Date: May 08, 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, 'Truncate TEMP_TXN_MEM', SYSDATE FROM DUAL;

   COMMIT;

   EXECUTE IMMEDIATE 'TRUNCATE TABLE SIEBEL_PURGE.TEMP_TXN_MEM';

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

   COMMIT;
END;
/

QUIT