BEGIN
    DECLARE
        V_COUNT NUMBER;
    BEGIN
        V_COUNT := 0;
        BEGIN
            SELECT COUNT(*)
              INTO V_COUNT
              FROM USER_SCHEDULER_JOBS
             WHERE JOB_NAME = 'JOB_DELETE_TMPDUPLICACOTACAO';
        EXCEPTION
            WHEN NO_DATA_FOUND THEN
            V_COUNT := 0;
        END;
        IF V_COUNT = 0 THEN
            DBMS_SCHEDULER.CREATE_JOB (
                job_name        => 'JOB_DELETE_TMPDUPLICACOTACAO',
                job_type        => 'PLSQL_BLOCK',
                job_action      => 'BEGIN DELETE_TMPDUPLICACOTACAO(); END;',
                start_date      => SYSDATE,
                repeat_interval => 'FREQ=DAILY; BYHOUR=0',
				end_date        => NULL,
                enabled         => TRUE,
                comments        => 'Job criado para excluir registros da tabela TMP_DUPLICACOTACAO.'
            );
        ELSE
            DBMS_SCHEDULER.DROP_JOB(JOB_NAME => 'JOB_DELETE_TMPDUPLICACOTACAO');
            DBMS_SCHEDULER.CREATE_JOB (
                job_name        => 'JOB_DELETE_TMPDUPLICACOTACAO',
                job_type        => 'PLSQL_BLOCK',
                job_action      => 'BEGIN DELETE_TMPDUPLICACOTACAO(); END;',
                start_date      => SYSDATE,
                repeat_interval => 'FREQ=DAILY; BYHOUR=0',
                end_date        => NULL,
                enabled         => TRUE,
                comments        => 'Job criado para excluir registros da tabela TMP_DUPLICACOTACAO.'
            );
        END IF;
    END;
END;
/