1建立实现任务的过程 在schema manager或SQL PLUS里建立如下过程 CREATE OR REPLACE PROCEDURE "CUSTOMER"."T_JOBTEST" as begin 0update emp set active =0 where active =1 and date_published < sysdate - active_days. end . 2 向任务队列中加入任务 在SQL PLUS中执行下列script VARIABLE jobno number. begin DBMS_JOB.SUBMIT(:jobno, t_jobtest(). , SYSDATE, SYSDATE 1 ). commit. end. 该任务立即执行(SYSDATE),并且每隔一天执行一次( SYSDATE 1 )。 3 查询此任务是否加入任务队列 在SQL PLUS中执行下列script SELECT job, next_date, next_sec, failures, broken FROM user_jobs. ------------------ DBMS_JOB 包介绍 调度任务队列里的任务要使用DBMS_JOB包中的过程。使用任务队列不需要特别的数据库特权。任何可以使用这些过程的用户都可以使用任务队列。 Table 8-2 DBMS_JOB包中的过程 Procedure Description Described SUBMIT Submits a job to the job queue. 向任务队列提交一个任务 REMOVE Removes a specified job from the job queue. 从任务队列中删除指定的任务 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. 改变任务 WHAT Alters the job description for a specified job. 改变指定任务的任务内容 NEXT_DATE Alters the next execution time for a specified job. 改变指定任务的下一次执行时间 INTERVAL Alters the interval between executions for a specified job. 改变指定任务的执行时间间隔。 BROKEN Disables job execution. If a job is marked as broken, Oracle does not attempt to execute it. 禁止指定任务的执行 RUN Forces a specified job to run. 强制执行指定的任务 Submitting a Job to the Job 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. describes the procedure s parameters. 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. 这里是你想执行的PL/SQL代码 For more information about defining a job, see "Job Definitions". next_date This is the next date when the job will be run. The default value is SYSDATE. 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 executed. If, for example, you want to submit a job before you have created the tables associated with the job, set NO_PARSE to TRUE. 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: