BEGIN
   DECLARE
      V_COUNT NUMBER;
   BEGIN
      V_COUNT := 0;
      BEGIN
         SELECT COUNT(*)
            INTO V_COUNT
            FROM USER_SCHEDULER_JOBS
           WHERE JOB_NAME = 'JOB_INSERT_PRODCOMPCOMPL';
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_COUNT := 0;
      END;
      IF V_COUNT = 0 THEN
         DBMS_SCHEDULER.CREATE_JOB (
            job_name        => 'JOB_INSERT_PRODCOMPCOMPL',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'BEGIN INSERT_PRODCOMPCOMPL(); END;',
            start_date      => SYSDATE,
            repeat_interval => 'FREQ=HOURLY; BYMINUTE=0',
            end_date        => NULL,
            enabled         => TRUE,
            comments        => 'Job criado para realizar a inserir produtos na tabela PRODCOMPCOMPL.'
         );
      ELSE
         DBMS_SCHEDULER.DROP_JOB(JOB_NAME => 'JOB_INSERT_PRODCOMPCOMPL');
         DBMS_SCHEDULER.CREATE_JOB (
            job_name        => 'JOB_INSERT_PRODCOMPCOMPL',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'BEGIN INSERT_PRODCOMPCOMPL(); END;',
            start_date      => SYSDATE,
            repeat_interval => 'FREQ=HOURLY; BYMINUTE=0',
            end_date        => NULL,
            enabled         => TRUE,
            comments        => 'Job criado para realizar a inserir produtos na tabela PRODCOMPCOMPL.'
         );
      END IF;
   END;
END;
/