1

If I submit a job via dbms_job.submit and I commit then it runs until completion. How much longer will it be available for me to view on the dba_jobs view and what determines this time?

Visionary Zen
  • 80
  • 1
  • 6
  • think it will be there till your schema exists. Furthermore, you should consider using `DBMS_SCHEDULER` over `DBMS_JOB`, which has become deprecated now. – Kaushik Nayak Jun 29 '18 at 08:26

1 Answers1

0

As @Kaushik said, the DBMS_JOB package has been superseeded by the DBMS_SCHEDULER package source. They have job names instead of numbers, a proper time scheduler language, and many views to monitor execution etc.

The DBMS_SCHEDULER.CREATE_JOB procedure has even a dedicated parameter for your question called auto_drop:

This flag if TRUE, causes the job to be automatically dropped after it has been completed. source

But you asked for DBMS_JOB, and I am rather sure that the job is not deleted. I just verified that it is removed when the user/schema is dropped.

As admin:

CREATE USER a IDENTIFIED BY a;
GRANT CREATE SESSION, CREATE JOB TO a;

As user a:

DECLARE
  my_job number;
BEGIN
  DBMS_JOB.SUBMIT(job => my_job, 
    what => 'BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(NULL); END;',
    next_date=>sysdate+(1/24/60),
    interval=>'sysdate+(1/24/60)');
  COMMIT;
end;
/   

As admin:

SELECT * FROM DBA_JOBS WHERE schema_user='A';
JOB LOG_USER LAST_DATE           NEXT_DATE ...
25  A        29.06.2018 13:46:25 29.06.2018 13:47:25

DROP USER A;
User A dropped.

SELECT * FROM DBA_JOBS WHERE schema_user='A';
no rows returned
wolφi
  • 8,091
  • 2
  • 35
  • 64