DECLARE
   V_JOB NUMBER;
   L_JOB_EXISTS NUMBER;
BEGIN
   FOR C_JOBS IN
      (SELECT JOB
       FROM USER_JOBS
       WHERE WHAT LIKE '%ETL_PLANEJADORA%'
   ) LOOP
      DBMS_JOB.REMOVE(C_JOBS.JOB);
   END LOOP;

   SELECT COUNT(*) INTO L_JOB_EXISTS
   FROM USER_SCHEDULER_JOBS
   WHERE JOB_NAME = 'JOB_ETL_PLANEJADORA';

   IF L_JOB_EXISTS = 1 THEN
       DBMS_SCHEDULER.DROP_JOB(JOB_NAME => 'JOB_ETL_PLANEJADORA');
   END IF;

   BEGIN
      DBMS_SCHEDULER.CREATE_JOB (
         JOB_NAME => 'JOB_ETL_PLANEJADORA',
         JOB_TYPE => 'PLSQL_BLOCK',
         JOB_ACTION => 'BEGIN ETL_PLANEJADORA(); COMMIT; END;',
         START_DATE => SYSDATE + 1,
         REPEAT_INTERVAL => 'FREQ=DAILY; BYHOUR=0; BYMINUTE=0; BYSECOND=0;',
         JOB_CLASS => '"DEFAULT_JOB_CLASS"',
         ENABLED => TRUE,
         AUTO_DROP => FALSE,
         COMMENTS => 'Job criado para planejadora.');
   END;
  COMMIT;   
END;
/