dbms_scheduler create_job repeat_interval 列子

文章 from oracle 官网

29.4.5 Setting the Repeat Interval

You can control when and how often a job repeats.

  • About Setting the Repeat Interval
    You control when and how often a job repeats by setting the repeat_interval attribute of the job itself or the named schedule that the job references. You can set repeat_interval with DBMS_SCHEDULER package procedures or with Cloud Control.
  • Using the Scheduler Calendaring Syntax
    The main way to set how often a job repeats is to set the repeat_interval attribute with a Scheduler calendaring expression.
  • Using a PL/SQL Expression
    When you need more complicated capabilities than the calendaring syntax provides, you can use PL/SQL expressions. You cannot, however, use PL/SQL expressions for windows or in named schedules. The PL/SQL expression must evaluate to a date or a timestamp.
  • Differences Between PL/SQL Expression and Calendaring Syntax Behavior
    There are important differences in behavior between a calendaring expression and PL/SQL repeat interval.
  • Repeat Intervals and Daylight Savings
    For repeating jobs, the next time a job is scheduled to run is stored in a timestamp with time zone column.

29.4.5.1 About Setting the Repeat Interval

You control when and how often a job repeats by setting the repeat_interval attribute of the job itself or the named schedule that the job references. You can set repeat_interval with DBMS_SCHEDULER package procedures or with Cloud Control.

Evaluating the repeat_interval results in a set of timestamps. The Scheduler runs the job at each timestamp. Note that the start date from the job or schedule also helps determine the resulting set of timestamps. If no value for repeat_interval is specified, the job runs only once at the specified start date.

Immediately after a job starts, the repeat_interval is evaluated to determine the next scheduled execution time of the job. While this might arrive while the job is still running, a new instance of the job does not start until the current one completes.

See Also:

Oracle Database PL/SQL Packages and Types Reference for more information about repeat_interval evaluation

29.4.5.2 Using the Scheduler Calendaring Syntax

The main way to set how often a job repeats is to set the repeat_interval attribute with a Scheduler calendaring expression.

See Also:

Oracle Database PL/SQL Packages and Types Reference for a detailed description of the calendaring syntax for repeat_interval as well as the CREATE_SCHEDULE procedure

Examples of Calendaring Expressions

The following examples illustrate simple repeat intervals. For simplicity, it is assumed that there is no contribution to the evaluation results by the start date.

Run every Friday. (All three examples are equivalent.)

FREQ=DAILY; BYDAY=FRI;
FREQ=WEEKLY; BYDAY=FRI;
FREQ=YEARLY; BYDAY=FRI;

Run every other Friday.

FREQ=WEEKLY; INTERVAL=2; BYDAY=FRI;

Run on the last day of every month.

FREQ=MONTHLY; BYMONTHDAY=-1;

Run on the next to last day of every month.

FREQ=MONTHLY; BYMONTHDAY=-2;

Run on March 10th. (Both examples are equivalent)

FREQ=YEARLY; BYMONTH=MAR; BYMONTHDAY=10;
FREQ=YEARLY; BYDATE=0310;

Run every 10 days.

FREQ=DAILY; INTERVAL=10;

Run daily at 4, 5, and 6PM.

FREQ=DAILY; BYHOUR=16,17,18;

Run on the 15th day of every other month.

FREQ=MONTHLY; INTERVAL=2; BYMONTHDAY=15;

Run on the 29th day of every month.

FREQ=MONTHLY; BYMONTHDAY=29;

Run on the second Wednesday of each month.

FREQ=MONTHLY; BYDAY=2WED;

Run on the last Friday of the year.

FREQ=YEARLY; BYDAY=-1FRI;

Run every 50 hours.

FREQ=HOURLY; INTERVAL=50;

Run on the last day of every other month.

FREQ=MONTHLY; INTERVAL=2; BYMONTHDAY=-1;

Run hourly for the first three days of every month.

FREQ=HOURLY; BYMONTHDAY=1,2,3;

Here are some more complex repeat intervals:

Run on the last workday of every month (assuming that workdays are Monday through Friday).

FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; BYSETPOS=-1

Run on the last workday of every month, excluding company holidays. (This example references an existing named schedule called Company_Holidays.)

FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; EXCLUDE=Company_Holidays; BYSETPOS=-1

Run at noon every Friday and on company holidays.

FREQ=YEARLY;BYDAY=FRI;BYHOUR=12;INCLUDE=Company_Holidays

Run on these three holidays: July 4th, Memorial Day, and Labor Day. (This example references three existing named schedules, JUL4MEM, and LAB, where each defines a single date corresponding to a holiday.)

JUL4,MEM,LAB

Examples of Calendaring Expression Evaluation

A repeat interval of "FREQ=MINUTELY;INTERVAL=2;BYHOUR=17; BYMINUTE=2,4,5,50,51,7;" with a start date of 28-FEB-2004 23:00:00 will generate the following schedule:

SUN 29-FEB-2004 17:02:00
SUN 29-FEB-2004 17:04:00
SUN 29-FEB-2004 17:50:00
MON 01-MAR-2004 17:02:00
MON 01-MAR-2004 17:04:00
MON 01-MAR-2004 17:50:00
...

A repeat interval of "FREQ=MONTHLY;BYMONTHDAY=15,-1" with a start date of 29-DEC-2003 9:00:00 will generate the following schedule:

WED 31-DEC-2003 09:00:00
THU 15-JAN-2004 09:00:00
SAT 31-JAN-2004 09:00:00
SUN 15-FEB-2004 09:00:00
SUN 29-FEB-2004 09:00:00
MON 15-MAR-2004 09:00:00
WED 31-MAR-2004 09:00:00
...

A repeat interval of "FREQ=MONTHLY;" with a start date of 29-DEC-2003 9:00:00 will generate the following schedule. (Note that because there is no BYMONTHDAY clause, the day of month is retrieved from the start date.)

MON 29-DEC-2003 09:00:00
THU 29-JAN-2004 09:00:00
SUN 29-FEB-2004 09:00:00
MON 29-MAR-2004 09:00:00
...

Example of Using a Calendaring Expression

As an example of using the calendaring syntax, consider the following statement:

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name             => ‘scott.my_job1‘,
   start_date           => ‘15-JUL-04 01.00.00 AM Europe/Warsaw‘,
   repeat_interval      => ‘FREQ=MINUTELY; INTERVAL=30;‘,
   end_date             => ‘15-SEP-04 01.00.00 AM Europe/Warsaw‘,
   comments             => ‘My comments here‘);
END;
/

This creates my_job1 in scott. It will run for the first time on July 15th and then run until September 15. The job is run every 30 minutes.

29.4.5.3 Using a PL/SQL Expression

When you need more complicated capabilities than the calendaring syntax provides, you can use PL/SQL expressions. You cannot, however, use PL/SQL expressions for windows or in named schedules. The PL/SQL expression must evaluate to a date or a timestamp.

Other than this restriction, there are no limitations, so with sufficient programming, you can create every possible repeat interval. As an example, consider the following statement:

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name             => ‘scott.my_job2‘, 
   start_date           => ‘15-JUL-04 01.00.00 AM Europe/Warsaw‘,
   repeat_interval      => ‘SYSTIMESTAMP + INTERVAL ‘30‘ MINUTE‘,
   end_date             => ‘15-SEP-04 01.00.00 AM Europe/Warsaw‘,
   comments             => ‘My comments here‘);
END;
/

This creates my_job1 in scott. It will run for the first time on July 15th and then every 30 minutes until September 15. The job is run every 30 minutes because repeat_interval is set to SYSTIMESTAMP + INTERVAL ‘30‘ MINUTE, which returns a date 30 minutes into the future.

29.4.5.4 Differences Between PL/SQL Expression and Calendaring Syntax Behavior

There are important differences in behavior between a calendaring expression and PL/SQL repeat interval.

These differences include the following:

  • Start date

    • Using the calendaring syntax, the start date is a reference date only. Therefore, the schedule is valid as of this date. It does not mean that the job will start on the start date.
    • Using a PL/SQL expression, the start date represents the actual time that the job will start executing for the first time.
  • Next run time

    As an example of the difference, for a job that is scheduled to start at 2:00 PM and repeat every 2 hours, but actually starts at 2:10:

    • If calendaring syntax specified the repeat interval, then it would repeat at 4, 6 and so on.
    • If a PL/SQL expression is used, then the job would repeat at 4:10, and if the next job actually started at 4:11, then the subsequent run would be at 6:11.
    • Using the calendaring syntax, the next time the job runs is fixed.
    • Using the PL/SQL expression, the next time the job runs depends on the actual start time of the current job run.

To illustrate these two points, consider a situation where you have a start date of 15-July-2003 1:45:00 and you want it to repeat every two hours. A calendar expression of "FREQ=HOURLY; INTERVAL=2; BYMINUTE=0;" will generate the following schedule:

TUE 15-JUL-2003  03:00:00
TUE 15-JUL-2003  05:00:00
TUE 15-JUL-2003  07:00:00
TUE 15-JUL-2003  09:00:00
TUE 15-JUL-2003  11:00:00
...

Note that the calendar expression repeats every two hours on the hour.

A PL/SQL expression of "SYSTIMESTAMP + interval ‘2‘ hour", however, might have a run time of the following:

TUE 15-JUL-2003  01:45:00
TUE 15-JUL-2003  03:45:05
TUE 15-JUL-2003  05:45:09
TUE 15-JUL-2003  07:45:14
TUE 15-JUL-2003  09:45:20
...
时间: 2024-10-25 02:05:30

dbms_scheduler create_job repeat_interval 列子的相关文章

dbms_job dbms_scheduler简单比较

---------------------------陈旧的-------------------------------------/*--------------------- 创建job ---------------------------  variable jobno number;    begin   dbms_job.submit(jobno,   'book_yuqi011;',    sysdate,    'sysdate+1/24/60');   commit;end;

Oracle Scheduler中的repeat_interval

Oracle 11g版本中引入了Scheduler(调度)来取代之前版本的JOB(任务).这里简单介绍一下Scheduler中repeat_interval参数的含义和使用方法. repeat_interval从字面意思来说就是重复间隔.是指用户定义间隔多长时间执行指定的任务.如果不指定该参数,则任务只执行一次. repeat_interval语法如下: repeat_interval = regular_schedule | combined_schedule   regular_schedu

使用DBMS_SCHEDULER包管理计划任务

Dbms_scheduler是Oracle提供创建计划任务的包,任务类型可以是执行PL\SQL程序.执行外部脚本.调用操作系统命令,通常用于创建定期定时的任务,不依赖操作系统,保存在数据库内,数据库迁移时不受影响,发生错误有日志可以查询,比较方便创建和使用.例如实施数据备份计划,将数据的备份的脚步保存在day_backup.sh 中,然后创建计划定期执行该脚步: $ vim /oracle/db_backup.sh #!/bin/sh ORACLE_SID=sydb; export ORACLE

Oracle定时任务(1)-DBMS_SCHEDULER

来自:http://blog.csdn.net/fw0124/article/details/6753715 Oracle 10g之前,可以使用dbms_job来管理定时任务.10g之后,Oracle引入dbms_scheduler来替代先前的dbms_job,在功能方面,它比dbms_job提供了更强大的功能和更灵活的机制/管理. 使用dbms_scheduler创建一个定时任务有两种形式1)创建1个SCHEDULER来定义计划,1个PROGRAM来定义任务内容,再创建1个JOB,为这个JOB

DBMS_SCHEDULER执行PERL脚本加载数据

1.例子利用oracle 11g 的dbms_scheduler包执行perl脚本加载数据文件,其中主要用到三个过程分别为SET_JOB_ARGUMENT_VALUE,CREATE_JOB,RUN_JOB三个过程,其中三个过程的参数说明如下: create_job参数: Attribute Description job_name Name of the job job_class Name of the job class job_style Style of the job: REGULAR

关于Oracle中job定时器(通过create_job创建的)配置示例

begin dbms_scheduler.create_job(job_name => 'JOB_BASIC_STATISTIC', job_type => 'STORED_PROCEDURE', job_action => 'PROC_BASIC_STATISTIC', --存储过程名 start_date => to_date(to_char(sysdate,'yyyy-mm-dd')||' 19:32:00', 'yyyy-mm-dd hh24:mi:ss'), REPEAT

oracle物化视图

原文URL: oracle 10g物化视图简介 2012-05-09 17:33:55|  分类: ORACLE性能 |  标签:oracle  物化视图  |举报|字号 订阅 下载LOFTER我的照片书  | 环境oracle 10g 10.2.0.4  linux 64 要大而专业的看oracle自己的文档-sql参考. 说实话,oracle需要学习的内容太多,每个都看过去,实在太费事. 所以如果能够对物化视图有个概览,那最方便不过. 主要涉及内容 物化视图日志,用于快速刷新所必须的 物化视

[转载]oracle物化视图

原文URL:http://lzfhope.blog.163.com/blog/static/636399220124942523943/?suggestedreading&wumii 环境oracle 10g 10.2.0.4  linux 64 要大而专业的看oracle自己的文档-sql参考. 说实话,oracle需要学习的内容太多,每个都看过去,实在太费事. 所以如果能够对物化视图有个概览,那最方便不过. 主要涉及内容 物化视图日志,用于快速刷新所必须的 物化视图 权限,通常不是个难题,因

小试牛刀-嘿嘿,创建job了

今天 周六,我写了这个存储过程.用意:检查 数据库中是否有 该类的 job,如果有那么取job_name  赋值给 job_old,    把job_old加上时间戳 改造成 job_new.那么job_old 和job_new 名称是相似的,完成第一步:第二步 if判断 ,如果系统中有 job,那么删除 旧的job.第三步 采用新的job_new 创建新的job.以此类推 CREATE OR REPLACE PROCEDURE CREATE_DROP_JOB_OK AS JOB_OLD_NAM