Solved

How do I prevent dbms_job from being re-executed.

Posted on 2006-11-09
6
395 Views
Last Modified: 2008-01-09

Hi,

I have submitted a job through dbms_job.submit package. Suppose, if anything goes wrong , I want the job to be broken and stop from being re-executed.
How do I achieve this?

One way of doing this is , if I see any error, I can use the dbms_job.broken package manually and remove the job from job queue.

But this is not what I am looking for.

 Is there any way that I can achieve this at the same time I submit the job and dont have to do it manually.


Thanks
0
Comment
Question by:sonaku2003
  • 2
6 Comments
 
LVL 6

Expert Comment

by:Ritesh_Garg
Comment Utility
How about doing this:
1.  Create a job which is not repeating (interval=null).
2.  If the job is successful, submit another job.

Will this work for you?

Thanks,
Ritesh
0
 
LVL 7

Expert Comment

by:lappins
Comment Utility
Try this:

BEGIN SYS.DBMS_JOB.BROKEN('<job_number>',TRUE); END;
0
 
LVL 7

Accepted Solution

by:
lappins earned 500 total points
Comment Utility
Use an exception handler in your job to BREAK the job if an unhandled exception occurrs, other wise  the job will keep resubmitting itself.

You submitted job may look something like this:

PROCEDURE MyJob

  l_job       BINARY_INTEGER;
  l_next DATE;
 
  CURSOR cur_job (b_what IN VARCHAR2) IS
    SELECT job
    FROM user_jobs
    WHERE what LIKE b_what;

BEGIN

  -- check that cursor is closed
  IF cur_job%ISOPEN THEN
    CLOSE cur_job;
  END IF;
 
  -- get job number
  OPEN cur_job ('MyJob');
  FETCH cur_job INTO l_job;
 
  IF cur_job%NOTFOUND THEN  
 
    --- submit the job here
      
      
  END IF;
 
  -- close cursor,
  CLOSE cur_job;

  --- now execute the intended procedure here
  package.procedure('a');
 
EXCEPTION
  WHEN OTHERS THEN
  -- break the job and end gracefully
    SYS.DBMS_JOB.BROKEN(l_job,TRUE);
END;
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now