您的位置:首页 > 其它

DBMS_SCHEDULER.CREATE_JOB

2013-04-07 10:33 495 查看
CREATE OR REPLACE PROCEDURE "SCOTT"."PRINT_NOW_TIME"
is
date_now_char varchar2(255);
begin
select to_char(sysdate,'yyyy/mm/dd HH:MI:SS') into date_now_char from dual;
dbms_output.put_line(date_now_char);
insert into date_time values(sysdate);
commit;
end;


 

BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name          =>  'TIME_JOB',
job_action      =>  'PRINT_NOW_TIME',
job_type        =>  'STORED_PROCEDURE',
repeat_interval   =>  'FREQ=MINUTELY',
comments          =>  'Daily at noon');
END;
/

 

 

begin
dbms_scheduler.enable('TIME_JOB');
end;


实现每分钟执行一次'TIME_JOB',即每分钟把当前时间插入date_time表

下面是参考的一部分

ENABLE Procedure

This procedure enables a program, job, chain, window, database destination, external destination, file watcher, or group. When an object is enabled, its
enabled
attribute is set to
TRUE
. By default, jobs, chains, and programs are created disabled and database destinations, external destinations, file watchers, windows, and groups are created enabled.

If a job was disabled and you enable it, the Scheduler begins to automatically run the job according to its schedule. Enabling a disabled job also resets the job
RUN_COUNT
,
FAILURE_COUNT
and
RETRY_COUNT
columns in the
*_SCHEDULER_JOBS
data dictionary views.

Validity checks are performed before enabling an object. If the check fails, the object is not enabled, and an appropriate error is returned. This procedure does not return an error if the object was already enabled.

Syntax
DBMS_SCHEDULER.ENABLE (
name              IN VARCHAR2,
commit_semantics  IN VARCHAR2 DEFAULT 'STOP_ON_FIRST_ERROR');

Parameters

Table 128-57 ENABLE Procedure Parameters
ParameterDescription
name


The name of the Scheduler object being enabled. Can be a comma-delimited list of names.

If a job class name is specified, then all the jobs in the job class are enabled.

If a group name is specified, then the group is enabled, but the enabled state of the group members is unaffected.

commit_semantics


The commit semantics. The following types are supported:

STOP_ON_FIRST_ERROR
- The procedure returns on the first error and previous successful enable operations are committed to disk. This is the default.

TRANSACTIONAL
- The procedure returns on the first error and everything that happened before that error is rolled back.

This type is only supported when enabling a job or a list of jobs.

ABSORB_ERRORS
- The procedure tries to absorb any errors and enable the rest of the jobs. It commits all the enable operations that were successful. If errors occur, you can query the view
SCHEDULER_BATCH_ERRORS
for details.

This type is only supported when enabling a job or a list of jobs.

Table 128-10 Values for repeat_interval

NameDescription
FREQ


This specifies the type of recurrence. It must be specified. The possible predefined frequency values are YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, and SECONDLY. Alternatively, specifies an existing schedule to use as a user-defined frequency.

INTERVAL


This specifies a positive integer representing how often the recurrence repeats. The default is 1, which means every second for secondly, every day for daily, and so on. The maximum value is 99.

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: