BEGIN
   DECLARE
      V_COUNT NUMBER;
   BEGIN
      V_COUNT := 0;
      BEGIN
         SELECT COUNT(*)
           INTO V_COUNT
           FROM USER_SCHEDULER_JOBS
          WHERE JOB_NAME = 'JOB_TOTALIZA_VENDAS_ORM';
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_COUNT := 0;
      END;
      IF V_COUNT = 0 THEN
         DBMS_SCHEDULER.CREATE_JOB (
            job_name        => 'JOB_TOTALIZA_VENDAS_ORM',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'BEGIN TOTALIZA_VENDAS_REL(); END;',
            start_date      => SYSDATE,
            repeat_interval => 'FREQ=DAILY;BYHOUR=1,6',
            end_date        => NULL,
            enabled         => TRUE,
            comments        => 'Job criado para atualizar vendas das tabela VENDASINT usando no Relatorio do Odhen Retail.'
         );
      ELSE
         DBMS_SCHEDULER.DROP_JOB(JOB_NAME => 'JOB_TOTALIZA_VENDAS_ORM');
         DBMS_SCHEDULER.CREATE_JOB (
            job_name        => 'JOB_TOTALIZA_VENDAS_ORM',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'BEGIN TOTALIZA_VENDAS_REL(); END;',
            start_date      => SYSDATE,
            repeat_interval => 'FREQ=DAILY;BYHOUR=1,6',
            end_date        => NULL,
            enabled         => TRUE,
            comments        => 'Job criado para atualizar vendas das tabela VENDASINT usando no Relatorio do Odhen Retail.'
         );
      END IF;
   END;
END;
/