CREATE_JOB¶
Use the CREATE_JOB procedure to create a job. The procedure comes in
two forms; the first form of the procedure specifies a schedule within
the job definition, as well as a job action that will be invoked when
the job executes:
CREATE_JOB(
<job_name> IN VARCHAR2,
<job_type> IN VARCHAR2,
<job_action> IN VARCHAR2,
<number_of_arguments> IN PLS_INTEGER DEFAULT 0,
<start_date> IN TIMESTAMP WITH TIME ZONE DEFAULT NULL,
<repeat_interval> IN VARCHAR2 DEFAULT NULL,
<end_date> IN TIMESTAMP WITH TIME ZONE DEFAULT NULL,
<job_class> IN VARCHAR2 DEFAULT 'DEFAULT_JOB_CLASS',
<enabled> IN BOOLEAN DEFAULT FALSE,
<auto_drop> IN BOOLEAN DEFAULT TRUE,
<comments> IN VARCHAR2 DEFAULT NULL)
The second form uses a job schedule to specify the schedule on which the job will execute, and specifies the name of a program that will execute when the job runs:
CREATE_JOB(
<job_name> IN VARCHAR2,
<program_name> IN VARCHAR2,
<schedule_name> IN VARCHAR2,
<job_class> IN VARCHAR2 DEFAULT 'DEFAULT_JOB_CLASS',
<enabled> IN BOOLEAN DEFAULT FALSE,
<auto_drop> IN BOOLEAN DEFAULT TRUE,
<comments> IN VARCHAR2 DEFAULT NULL)
Parameters
job_name
job_namespecifies the optionally schema-qualified name of the job being created.
job_type
job_typespecifies the type of job. The current implementation ofCREATE_JOBsupports a job type ofPLSQL_BLOCKorSTORED_PROCEDURE.
job_action
If
job_typeisPLSQL_BLOCK,job_actionspecifies the content of the PL/SQL block that will be invoked when the job executes. The block must be terminated with a semi-colon (;).If
job_typeisSTORED_PROCEDURE,job_actionspecifies the optionally schema-qualified name of the procedure.
number_of_arguments
number_of_argumentsis anINTEGERvalue that specifies the number of arguments expected by the job. The default is0.
start_date
start_dateis aTIMESTAMP WITH TIME ZONEvalue that specifies the first time that the job is scheduled to execute. The default value isNULL, indicating that the job should be scheduled to execute when the job is enabled.
repeat_interval
repeat_intervalis aVARCHAR2value that specifies how often the job will repeat. If arepeat_intervalis not specified, the job will execute only once. The default value isNULL.
end_date
end_dateis aTIMESTAMP WITH TIME ZONEvalue that specifies a time after which the job will no longer execute. If a date is specified, theend_datemust be afterstart_date. The default value isNULL.Please note that if an
end_dateis not specified and arepeat_intervalis specified, the job will repeat indefinitely until it is disabled.
program_name
program_nameis the name of a program that will be executed by the job.
schedule_name
schedule_nameis the name of the schedule associated with the job.
job_class
job_classis accepted for compatibility and ignored.
enabled
enabledis aBOOLEANvalue that specifies if the job is enabled when created. By default, a job is created in a disabled state, withenabledset toFALSE. To enable a job, specify a value ofTRUEwhen creating the job, or enable the job with theDBMS_SCHEDULER.ENABLEprocedure.
auto_drop
The
auto_dropparameter is accepted for compatibility and is ignored. By default, a job’s status will be changed toDISABLEDafter the time specified inend_date.
comments
Use the
commentsparameter to specify a comment about the job.
Example
The following example demonstrates a call to the CREATE_JOB procedure:
EXEC
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'update_log',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN INSERT INTO my_log VALUES(current_timestamp);
END;',
start_date => '01-JUN-15 09:00:00.000000',
repeat_interval => 'FREQ=DAILY;BYDAY=MON,TUE,WED,THU,FRI;BYHOUR=17;',
end_date => NULL,
enabled => TRUE,
comments => 'This job adds a row to the my_log table.');
The code fragment creates a job named update_log that executes each
weeknight at 5:00. The job executes a PL/SQL block that inserts the
current timestamp into a logfile (my_log). Since no end_date is
specified, the job will execute until it is disabled by the DBMS_SCHEDULER.DISABLE procedure.