1 Establish a process of implementing tasks
Established the following process in Schema Manager or SQL Plus
Create or Replace Procedure "Customer". "T_jobtest" asbegin
Update EMP SET ACTIVE = 0 Where active = 1 and Date_Published END; 2 Add tasks to the task queue Perform the following Script in SQL Plus Variable Jobno Number; Begin dbms_Job.Submit (: Jobno, 'T_Jobtest ();', sysdate, 'sysdate 1'); commit; end; this task is executed immediately (sysdate), and execute once every other day ('sysdate 1'). 3 Query this task to join the task queue Perform the following Script in SQL Plus Select Job, Next_Date, Next_Sec, Failures, Brokenfrom User_jobs; ------------------ DBMS_JOB package introduction The task in the dispatch task queue is to use the process in the DBMS_JOB package. Use the task queue without special database privileges. Any user who can use these procedures can use task queues. Process in the Table 8-2 DBMS_JOB package Procedure Description Described SUBMIT Submits a job to the job queue. Submitted to the task queue a task REMOVE Removes a specified job from the job queue. Delete specified in the task queue task CHANGE Alters a specified job. You can alter the job description, the time at which the job will be run, or the interval between executions of the job. change task WHAT Alters the job description for a specified job. change the designation of the task of the task content NEXT_DATE Alters the next execution time for a specified job. change the designation of the task The next execution time Interval Alters The Interval Between Executions for a specified job. Change the execution time interval of the specified task. Broken Disables JOB EXECUTION. IF a Job Is Marked As Broken, Oracle Does Not Attempt to Execute IT. Doing the Specifies the Task for Run forces a Specified Job To Run. Force the specified task Submitting a job to the job queUE submits a task to the task queue To Submit a New Job To the Job Queue, Use The Submit Procedure In The DBMS_JOB PACKAGE: DBMS_JOB.SUBMIT (job OUT BINARY_INTEGER, what IN VARCHAR2, next_date IN DATE DEFAULT SYSDATE, interval IN VARCHAR2 DEFAULT 'null', no_parse IN BOOLEAN DEFAULT FALSE) The SUBMIT procedure returns the number of the job you submitted. Table 8-3 describes the Procedure's parameters. Parameters for Table 8-3 dbms_Job.Submit Parameter Description job This is the identifier assigned to the job you created. You must use the job number whenever you want to alter or remove the job. For more information about job numbers, see "Job Numbers". What This is the PL / SQL Code You Want To Have Executed. This is the PL / SQL code for doing a job, see "job definitions". Next_date this is the next date... interval This is the date function that calculates the next time to execute the job. The default value is NULL. INTERVAL must evaluate to a future point in time or NULL. For more information on how to specify an execution interval, see "Job Execution Interval ". no_parse This is a flag. The default value is FALSE. If nO_PARSE is set to FALSE (the default), Oracle parses the procedure associated with the job. If nO_PARSE is set to TRUE, Oracle parses the procedure associated with the job the First Time That The Job Is EX Ecuted. If As an example, let's submit a new job to the job queue. The job calls the procedure DBMS_DDL.ANALYZE_OBJECT to generate optimizer statistics for the table DQUON.ACCOUNTS. 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; Begin 2> DBMS_Job.Submit (: Jobno, 3> 'DBMS_DDL.Alyze_Object (' 'Table', 4> 'DQUON', '' Accounts', 5> '' Estimate '', NULL, 50); '6> Sysdate,' sysdate 1 '); 7> Commit; 8> end; 9> / statement processed.print Jobnojobno ---------- 14144 Job Definition Task Definition Task definition is the PL / SQL code specified in the WHAT parameter during the Submit process. Usually the task definition (content) is a call for a process. This process can have any number of parameters. NOTE: IN THE JOB Definition, Use two, quotation Marks Around Strings. ALWAYS INCLUDE A SEMICOLON AT THE End of the Job Definition. In task definitions, the string is surrounded by 2 single quotes. Task definitions always take a semicolon. Jobs and Import / Export Jobs can be exported and imported. Thus, if you define a job in one database, you can transfer it to another database. When exporting and importing jobs, the job's number, environment, and definition remain unchanged. The task is to be unloaded (Imported). Job Execution Interval Task Execution Interval The INTERVAL date function is evaluated immediately before a job is executed. If the job completes successfully, the date calculated from INTERVAL becomes the new NEXT_DATE. If the INTERVAL date function evaluates to NULL and the job completes successfully, the job is deleted from the queue . IF a Job Should Be Executed Periodical AT A Set Interval, Use a Date Expression Similar To 'Sysdate 7' in The Interval If you always want to automatically execute a job at a specific time, regardless of the last execution (for example, every Monday), the INTERVAL and NEXT_DATE parameters should specify a date expression similar to 'NEXT_DAY (TRUNC (SYSDATE), "MONDAY" ) '. Table 8-5 Lists Some Common Date Expressions Used for Job Execution Interval. Table 8-5 Common Job Execution Interval Date Expression Evaluation 'Sysdate 7' Exactly seven day from the last execution 7 days after the last execution 'Sysdate 1/48' Every Half Hour Perform a time every half hour 'Next_day (trunc (tysdate), '' Monday '') 15/24 ' Every Monday AT 3PM Each week is one of 3 o'clock in the afternoon 'Next_day (add_months (trunc (sysdate,' 'q' '), 3), '' Thursday '') ' First Thursday of Each Quarter's first Thursday every quarter Note: When specifying next_date or interval Removing a job from the job queue Removes the task in the task queue To Remove a Job from The Job Queue, Use The Remove Procedure In The DBMS_JOB PACKAGE: DBMS_Job.Remove (Job in binary_integer) The Following Statement Removes Job Number 14144 from the Job Queue: DBMS_Job.Remove (14144); SYNTAX for What You can alter the definition of a job by calling the dbms_job.what procedure. Table 8-3 Describes The Procedure's Parameters. DBMS_Job.What (Job in Binary_INTEGER, What in varchar2) Note: WHEN You Execute Procedure What, Oracle Records Your Current Environment. This Becomes The New Environment for the Job. SYNTAX for next_date YOU CAN ALTER THE NEXT date That Oracle Executes a job by calling the dbms_job.next_date procedure. Table 8-3 Describes the procedure's parameters.dbms_job.next_date (Job in binary_integer, Next_date in date Syntax for Interval You can alter The Execution Interval of a job by calling the dbms_job.interval procedure. Table 8-3 Describes The Procedure's Parameters. DBMS_Job.Iterval (Job in Binary_INTEGER, Interval in varchar2) Viewing Job Queue Information Information Query Task Queue You can query information in the task queue through the data dictionary view in the table below. Table 8-6 View of the task queue information View Description DBA_JOBS Lists all the jobs in the database. Lists tasks in the database User_jobs Lists all jobs oowned by the user. Lists the task owned by the user DBA_JOBS_RUNNING Lists All Jobs in The Database That Are Currently Running. This View Joins V $ LOCK AND JOB $. Lists the currently running tasks. For example, you can display information about a job's status and failed executions The following sample query creates a listing of the job number, next execution time, failures, and broken status for each job you have submitted.: Displays the status of the task and the number of failures. Select Job, Next_Date, Next_sec, Failures, Broken From user_jobs; Job next_date next_sec failies B ---------- ------------------------ 9125 01-NOV-94 00:00:00 4 N 14144 24-OCT-94 16:35:35 0 n 41762 01-Jan-00 00:00:00 16 Y 3 rows selected. You can also display information about jobs currently running The following sample query lists the session identifier, job number, user who submitted the job, and the start times for all currently running jobs.: Displays information about the currently running task. SELECT SID, R.JOB, LOG_USER, R.THIS_DATE, 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 JFEE 24-OCT-94 17:21:24 25 8536 Scott 24-Oct-94 16:45:12 2 rows selected. The reprinator has added: actual development may encounter a certain time to perform scripts for a month, can be implemented using add_months (to_date (sysdate (sysdate, 'YYYYMMDDD'), 1), this script will be one Performed once. For example: VARIABLE jobno number; begin DBMS_JOB.SUBMIT (: jobno, 'p_procedure;', to_date (sysdate, 'yyyymmdd'), 'Add_months (to_date (' sysdate ',' 'yyyymmdd' '), 1)'); commit . parameter. For example, if you set the execution interval to 'SYSDATE 7' on Monday, but for some reason (such as a network failure) the job is not executed until Thursday, 'SYSDATE 7' then executes every Thursday, not Monday.