oracle 每天安排几个小时的工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14337075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:23:10  来源:igfitidea点击:

job scheduling for a few hours everyday

oracleplsqloracle11gschedulingjobs

提问by Jaanna

I need to schedule a job starting from 0600 till 1800. The job should run after every two hours. For example 0800, 1000, 1200, 1400, 1600, 1800.

我需要安排从 0600 到 1800 的作业。该作业应每两小时运行一次。例如 0800、1000、1200、1400、1600、1800。

Here is the code I have managed to do so far:

这是我迄今为止设法做到的代码:

DECLARE
     l_id binary_integer;
     begin
       sys.dbms_job.submit(job => l_id, what => 'integration_export;', interval => 'TRUNC(SYSDATE,''hh24'')+0/24/60');
       sys.dbms_output.put_line(l_id);    
end; 

This will, of course, run the job after every 2 hours without stopping at 1801 - 0759. How may I add this restriction? One thing I though is to create another schedule procedure which wakes up at 1801 and changes NEXT_DATE for this job. However, I am wondering if it is a good idea.

当然,这将每 2 小时运行一次作业,而不会在 1801 - 0759 停止。我如何添加此限制?我认为的一件事是创建另一个计划程序,该程序在 1801 唤醒并更改此作业的 NEXT_DATE。但是,我想知道这是否是一个好主意。

Any suggestions?

有什么建议?

Thanks in advance :-)

提前致谢 :-)

回答by DazzaL

dbms_jobis old. I'd recomend you use the dbms_scheduler(introduced in Oracle 10g) instead.

dbms_job老了。我建议您改用dbms_scheduler(在 Oracle 10g 中引入)。

dbms_scheduler.create_job(job_name        => 'YOUR_JOB',
                          job_type        => 'PLSQL_BLOCK', 
                          job_action      => 'integration_export;',
                          start_date      => systimestamp,
                          repeat_interval => 'freq=hourly; byhour=8,10,12,14,16,18; byminute=0; bysecond=0;',
                      enabled         => true,
                      auto_drop       => false,
                      comments        => 'some comment about the job');

回答by Alen Oblak

Instead of dmbs_job, use the advanced dbms_scheduler. Here is an example:

使用高级 dbms_scheduler 代替 dmbs_job。下面是一个例子:

begin
  DBMS_SCHEDULER.create_job (
    job_name        => 'Integration_export',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'integration_export;',
    start_date      => SYSTIMESTAMP,
    enabled         => TRUE,
    repeat_interval => 'freq=daily; byhour=6,8,10,12,14,16,18; byminute=0; bysecond=0');
end;
/