We have 5 jobs submitted through dbmsjobs, which get executed every hour. Now sometimes some of the jobs dont get finished and get broken. How can I automatically resubmit a job, without the user intervention. Is there a routine which can for example check at every 20 minutes whether the jobs are working fine. What if this routine fails?
Security ModelNo specific system privileges are required to use DBMSJOB. No system privileges are available to manage DBMSJOB. Jobs cannot be altered or deleted other than jobs owned by the user. This is true for all users including those users granted DBA privileges.You can execute procedures that are owned by the user or for which the user is explicitly granted EXECUTE. However, procedures for which the user is granted the execute privilege through roles cannot be executed.Note that, once a job is started and running, there is no easy way to stop the job. Working with Oracle Real Application ClustersDBMSJOB supports multi-instance execution of jobs.
By default jobs can be executed on any instance, but only one single instance will execute the job. In addition, you can force instance binding by binding the job to a particular instance. You implement instance binding by specifying an instance number to the instance affinity parameter.
Note, however, that in Oracle Database 10g Release 1 (10.1) instance binding is not recommended. Service affinity is preferred. This concept is implemented in the package.The following procedures can be used to create, alter or run jobs with instance affinity. Note that not specifying affinity means any instance can run the job. DBMSJOB.SUBMITTo submit a job to the job queue, use the following syntax:DBMSJOB.SUBMIT(job OUT BINARYINTEGER,what IN VARCHAR2,nextdate IN DATE DEFAULT SYSDATE,interval IN VARCHAR2 DEFAULT 'NULL',noparse IN BOOLEAN DEFAULT FALSE,instance IN BINARYINTEGER DEFAULT ANYINSTANCE,force IN BOOLEAN DEFAULT FALSE);Use the parameters instance and force to control job and instance affinity.
The default value of instance is 0 (zero) to indicate that any instance can execute the job. To run the job on a certain instance, specify the instance value. Oracle displays error ORA-23319 if the instance value is a negative number or NULL.The force parameter defaults to false. If force is TRUE, any positive integer is acceptable as the job instance.
If force is FALSE, the specified instance must be running, or Oracle displays error number ORA-23428. DBMSJOB.INSTANCETo assign a particular instance to execute a job, use the following syntax:DBMSJOB.INSTANCE( JOB IN BINARYINTEGER,instance IN BINARYINTEGER,force IN BOOLEAN DEFAULT FALSE);The FORCE parameter in this example defaults to FALSE. If the instance value is 0 (zero), job affinity is altered and any available instance can execute the job despite the value of force. If the INSTANCE value is positive and the FORCE parameter is FALSE, job affinity is altered only if the specified instance is running, or Oracle displays error ORA-23428.If the force parameter is TRUE, any positive integer is acceptable as the job instance and the job affinity is altered. Oracle displays error ORA-23319 if the instance value is negative or NULL. DBMSJOB.CHANGETo alter user-definable parameters associated with a job, use the following syntax:DBMSJOB.CHANGE( JOB IN BINARYINTEGER,what IN VARCHAR2 DEFAULT NULL,nextdate IN DATE DEFAULT NULL,interval IN VARCHAR2 DEFAULT NULL,instance IN BINARYINTEGER DEFAULT NULL,force IN BOOLEAN DEFAULT FALSE );Two parameters, instance and force, appear in this example. The default value of instance is null indicating that job affinity will not change.The default value of force is FALSE.
Oracle displays error ORA-23428 if the specified instance is not running and error ORA-23319 if the instance number is negative. Table 84-1 DBMSJOB Package Subprograms SubprogramDescriptionDisables job executionAlters any of the user-definable parameters associated with a jobAssigns a job to be run by a instanceAlters the interval between executions for a specified jobAlters the next execution time for a specified jobRemoves specified job from the job queueForces a specified job to runSubmits a new job to the job queueRe-creates a given job for export, or re-creates a given job for export with instance affinityAlters the job description for a specified job. Table 84-3 CHANGE Procedure Parameters ParameterDescriptionjobSystem-assigned ID of the job being run.
To find this ID, query the JOB column of the USERJOBS or DBAJOBS view.whatPL/SQL procedure to run.nextdateNext date when the job will be run.intervalDate function; evaluated immediately before the job starts running.instanceWhen a job is submitted, specifies which instance can run the job. This defaults to NULL, which indicates that instance affinity is not changed.forceIf this is FALSE, then the specified instance (to which the instance number change) must be running. Otherwise, the routine raises an exception.If this is TRUE, then any positive integer is acceptable as the job instance. Table 84-9 SUBMIT Procedure Parameters ParameterDescriptionjobSystem-assigned ID of the job being run. To find this ID, query the JOB column of the USERJOBS or DBAJOBS viewwhatPL/SQL text o the job to be run.
This must be a valid PL/SQL statement or block of code. For example, to run a stored procedure P, you could pass the string P; (with the semi-colon) to this routine. The SQL that you submit in the what parameter is wrapped in the following PL/SQL block:DECLAREjob BINARYINTEGER:=:job;nextdate DATE:=:mydate;broken BOOLEAN:= FALSE;BEGINWHAT:mydate:= nextdate;IF broken THEN:b:= 1; ELSE:b:= 0; END IF;END;Ensure that you include the; semi-colon with the statement.nextdateNext date when the job will be run.intervalDate function that calculates the next time to run the job. The default is NULL.
This must evaluate to a either a future point in time or NULL.noparseA flag. The default is FALSE. If this is set to FALSE, then Oracle parses the procedure associated with the job.
If this is set to TRUE, then Oracle parses the procedure associated with the job the first time that the job is run.For example, if you want to submit a job before you have created the tables associated with the job, then set this to TRUE.instanceWhen a job is submitted, specifies which instance can run the job.forceIf this is TRUE, then any positive integer is acceptable as the job instance. If this is FALSE (the default), then the specified instance must be running; otherwise the routine raises an exception. ExampleThis submits a new job to the job queue. The job calls the procedure DBMSDDL. ANALYZEOBJECT to generate optimizer statistics for the table DQUON.
![Submit Dbms_job Examples Submit Dbms_job Examples](http://www.dba-oracle.com/images/tips_oracle_dbms_job.gif)
The statistics are based on a sample of half the rows of the ACCOUNTS table. The job is run every 24 hours:VARIABLE jobno number;BEGINDBMSJOB.SUBMIT(:jobno,'dbmsddl.analyzeobject('TABLE','DQUON', 'ACCOUNTS','ESTIMATE', NULL, 50);'SYSDATE, 'SYSDATE + 1');COMMIT;END;/Statement processed.print jobnoJOBNO-14144.
Question: Execute immediate within a DBMSJOBCan I do a dynamic SQL WITHIN A DBMSJOB. Here is how my job looks like.————————————————————————————————————DECLAREX NUMBER;viewDDL VARCHAR2(30000);BEGINviewDDL:= myPkg.getViewDDL;SYS.DBMSJOB.SUBMIT( job = X,what = viewDDL,nextdate = todate(’ 10:50:38′,’dd/mm/yyyy hh24:mi:ss’),interval = ‘SYSDATE+1/1440 ‘,noparse = TRUE);SYS.DBMSOUTPUT.PUTLINE(‘Job Number is: ‘ tochar(x));END;/——————————————————————————————————————–The viewDDL is dynamic and can change from time to time. That’s why it is in a package and myPkg.getViewDDL returns the CREATE OR REPLACE VIEW statement.Any ideas why this is not working?Solution: Execute immediate within a DBMSJOBHi! This seems to be a rights restrictions problem.