BEGIN
   DECLARE
      V_COUNT NUMBER;
   BEGIN
      V_COUNT := 0;
      BEGIN
         SELECT COUNT(*)
           INTO V_COUNT
           FROM USER_SCHEDULER_JOBS
          WHERE JOB_NAME = 'APURACAO_DRF_AUT';
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_COUNT := 0;
      END;
      IF V_COUNT = 0 THEN
         DBMS_SCHEDULER.CREATE_JOB (
            job_name        => 'APURACAO_DRF_AUT',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'BEGIN JOB_APURACAO_DRF(); END;',
            start_date      => SYSDATE,
            repeat_interval => 'FREQ=DAILY; BYHOUR=0',
            end_date        => NULL,
            enabled         => TRUE,
            comments        => 'Job criado para realizar a apuracao do DRF de forma automatica.'
         );
      ELSE
         DBMS_SCHEDULER.DROP_JOB(JOB_NAME => 'APURACAO_DRF_AUT');
         DBMS_SCHEDULER.CREATE_JOB (
            job_name        => 'APURACAO_DRF_AUT',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'BEGIN JOB_APURACAO_DRF(); END;',
            start_date      => SYSDATE,
            repeat_interval => 'FREQ=DAILY; BYHOUR=0',
            end_date        => NULL,
            enabled         => TRUE,
            comments        => 'Job criado para realizar a apuracao do DRF de forma automatica.'
         );
      END IF;
   END;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('AGENDA_APURACAO_DRF','6.10.000'); END;
/
