0

I have a procedure that is supposed to selectively purge jobs from the system. It uses dbms_schedule.drop_job to perform this.

I want to be able to loop through a group of jobs in a cursor dropping each one. If an exception is thrown because the job does not exist, I want to catch the exception and continue looping.

Ollie
  • 17,058
  • 7
  • 48
  • 59
drouleau
  • 35
  • 5

1 Answers1

2

There's no real need to do this. Why don't you just inner join your cursor to ALL_SCHEDULER_JOBS, using the correct schema and job name?

That way you're guaranteed that the job does exist. If you want to do something other than ignoring the error, for instance updating the list, you can easily do it in code; there's no need to use an exception for flow control.

If you really wanted to use an exception then you can use a user defined exception. Alternatively (not necessarily a good idea) catch absolutely everything; for instance:

begin
   -- some stuff
   begin
      dbms_scheduler.drop_job(job_name => 'my_job');
   exception when others then
      -- do some stuff
   end;

end;
Community
  • 1
  • 1
Ben
  • 51,770
  • 36
  • 127
  • 149