CREATE OR REPLACE PROCEDURE LIMPA_CONSPLAN_JOB
IS
   V_COUNT NUMBER;
BEGIN
   V_COUNT := 0;
   FOR C_CONSPLAN IN (SELECT ROWID AS LINHA
                      FROM CONSPLAN) LOOP
      DELETE CONSPLAN
      WHERE ROWID = C_CONSPLAN.LINHA;

      V_COUNT := V_COUNT+1;
      IF V_COUNT >= 800 THEN
         COMMIT;
         V_COUNT := 0;
      END IF;
   END LOOP;

   DBMS_STATS.GATHER_TABLE_STATS('TEKNISA', 'CONSPLAN', CASCADE=>TRUE);
END;
/

DECLARE
   V_JOB NUMBER;
BEGIN
   FOR C_JOBS IN (SELECT JOB
                  FROM ALL_JOBS
                  WHERE WHAT = 'LIMPA_CONSPLAN_JOB') LOOP
      DBMS_JOB.REMOVE(C_JOBS.JOB);
   END LOOP;

   DBMS_JOB.SUBMIT(V_JOB,
   WHAT => 'BEGIN LIMPA_CONSPLAN_JOB(); END;',
   NEXT_DATE => TO_DATE(TRUNC(SYSDATE) + 0.99999, 'DD/MM/YYYY HH24:MI:SS'),
   INTERVAL=> 'TRUNC(SYSDATE) + 0.99999');
   COMMIT;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('LIMPA_CONSPLAN_JOB','6.05.000'); END;
/
