Oracle JOB usage Summary 1. set the initialization parameter job_queue_processes SQL> alter system set job_queue_processes = n; (n> 0) the maximum value of job_queue_processes is 1000. view the SQL> select name of the job queue background process, description from v $ bgprocess; 2. the usage of dbms_job package includes the following sub-processes: Broken () process. Change () process. Interval () process. Isubmit () process. Next_Date () process. Remove () process. Run () process. Submit () process. User_Export () process. What () process. 1. The Broken () process updates the status of a submitted job. It is typically used to mark a Broken job as a non-Broken job. Www.2cto.com has three parameters: job, broken, and next_date. PROCEDURE Broken (job IN binary_integer, Broken IN boolean, next_date IN date: = SYSDATE) the job parameter is the work number, which uniquely identifies the work IN the problem. The broken parameter indicates whether the job is marked as broken -- TRUE indicates that the job is marked as broken, and FLASE indicates that the job is marked as not broken. The next_date parameter indicates when the job will run again. The default value of this parameter is the current date and time. If a job fails for some reason, oracle will retry 16 times and fail to execute successfully. It will be marked as a job in broken restart status, there are two methods: a. Use dbms_job.run () to immediately execute the job SQL> begin SQL> dbms_job.run (: jobno). The jobno is the job number SQL> end returned when the submit process is submitted; SQL>/B. Use dbms_job.broken () to re-mark the broken as false SQL> begin SQL> dbms_job.broken (: job, false, next_date) SQL> end; SQL>/2. The Change () process is used to Change the settings of a specified job. This process has four parameters: job, what, next_date, and interval. PROCEDURE Change (job IN binary_integer, What IN varchar2, next_date IN date, interval IN varchar2) www.2cto.com this job parameter is an integer that uniquely identifies the job. The What parameter is a PL/SQL code block that runs from this job. The next_date parameter indicates when the job will be executed. The interval parameter indicates the frequency of re-execution. 3. The Interval () process is used to explicitly set the time Interval between re-execution of a job. This process has two parameters: job and interval. PROCEDURE Interval (job IN binary_integer, Interval IN varchar2) the job parameter identifies a specific job. The interval parameter indicates the frequency of re-execution. 4. The ISubmit () process is used to submit a job with a specific job number. This process has five parameters: job, what, next_date, interval, and no_parse. PROCEDURE ISubmit (job IN binary_ineger, What IN varchar2, next_date IN date, interval IN varchar2, no_parse IN booean: = FALSE) This process corresponds to Submit () the only difference IN the process is that this job parameter is passed as an IN parameter and includes a working number provided by the developer. If the provided work number is used, an error is generated. 5. The Next_Date () process is used to explicitly set the execution time of a job. This process receives two parameters: job and next_date. Www.2cto.com PROCEDURE Next_Date (job IN binary_ineger, next_date IN date) indicates an existing job. The next_date parameter indicates the date and time when the job should be executed. 6. Remove () to delete a scheduled job. This process receives a parameter PROCEDURE Remove (job IN binary_ineger), which uniquely identifies a job. The value of this parameter is the value of the job parameter returned when Submit () is called for this job. A running job cannot be deleted by a called program. 7. The Run () process is used to immediately execute a specified job. This process only receives one parameter: PROCEDURE Run (job IN binary_ineger) job parameter identifier for the job to be executed immediately. 8. Use the Submit () process and the work is properly planned. This process has five parameters: job, what, next_date, interval, and no_parse. PROCEDURE Submit (job OUT binary_ineger, What IN varchar2, next_date IN date, interval IN varchar2, no_parse IN booean: = FALSE) the job parameter is the binary_ineger returned by the Submit () process. This value uniquely identifies a job. What parameter is the PL/SQL code block to be executed. The next_date parameter specifies when the job will be run. The interval parameter indicates when the job will be re-executed. The no_parse parameter indicates whether the job should perform syntax analysis at the time of submission or execution -- TRUE indicates that the PL/SQL code should perform syntax analysis during its first execution, FALSE indicates that the PL/SQL code should be analyzed immediately. 9. A command is returned during the User_Export () process. This command is used to schedule an existing job so that the job can be submitted again. This program has two parameters: job and my_call. The PROCEDURE User_Export (job IN binary_ineger, my_call in out varchar2) www.2cto.com job parameter identifies a scheduled job. The my_call parameter contains the body required to resubmit the job in its current state. 10. What () process promises to reset the running command during job execution. This process receives two parameters: job and what. PROCEDURE What (job IN binary_ineger, What in out varchar2) the job parameter identifies an existing job. What parameter indicates the new PL/SQL code to be executed. 3. View related job information 1. View related dba_jobs all_jobs user_jobs dba_jobs_running contains information about running jobs 2. View related information SQL> SELECT job, NEXT_DATE, NEXT_SEC, FAILURES, broken SQL> FROM DBA_JOBS; www.2cto.com JOB NEXT_DATE NEXT_SEC failures B ------- --------- ---------9125 01-JUN-01 00:00:00 4 N 14144 24--01 -01 16:35:35 0 N 9127 01-JUN-01 00:00:00 16 Y 3 rows selected. select sid, r. JOB, LOG_USER, r. THIS_DAT E, r. THIS_SEC FROM DBA_JOBS_RUNNING r, DBA_JOBS j WHERE r. JOB = j. JOB; sid job LOG_USER THIS_DATE THIS_SEC ----- ---------- ------------- --------- -------- 12 14144 HR 24-OCT-94 17:21:24 25 8536 QS 24-OCT-94 16:45:12 2 rows selected. select sid, TYPE, ID1, ID2 from v $ lock where type = 'jq'; sid ty ID1 ID2 --------- -- --------- 12 JQ 0 14144 1 row selected. 4. A simple example Single example: create a TEST table SQL> create table TEST (a date); www.2cto.com has been created. Create a custom process SQL> create or replace procedure MYPROC as begin insert into TEST values (sysdate); end;/the process has been created. Create job SQL> variable job1 number; SQL> begin dbms_job.submit (: job1, 'myproc; ', sysdate, 'sysdate + 100'); -- 1/1440 minutes a day, that is, the test process is run once at one minute. The/PL/SQL process is successfully completed. Run job SQL> begin dbms_job.run (: job1); end;/PL/SQL. Www.2cto.com SQL> select to_char (a, 'yyyy/mm/dd hh24: mi: ss') time from TEST; time Interval 2001/01/07 23:51:21 2001/01/07 23:52:22 2001/01/07 23:53:24 Delete job SQL> begin dbms_job.broken (jobno, true); end;/SQL> begin dbms_job.remove (: job1); end; the/PL/SQL process is successfully completed. Author Alex 'sky