我需要在oracle中为运行作业创建计划。它将在每个月的第一个工作日运行,但不包括假期。当月的第一个工作日是假日时,比运行应该是假期后的下一个工作日。
我在每个月的第一个工作日管理并排除假期,但我不知道如何在假期后设置工作日运行...
假日
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'SCHDL_COM_HOLIDAYS',
repeat_interval => 'FREQ=YEARLY; BYDATE=0101,0111;'
);
第一个工作日
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'SCHDL_FIRST_WD',
repeat_interval => 'FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; EXCLUDE=SCHDL_COM_HOLIDAYS; BYSETPOS=1'
);
答案 0 :(得分:1)
请按照以下步骤操作:
1)为所有假期创建时间表。
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'NYD_FRI',
repeat_interval => 'FREQ=YEARLY;BYDATE=1231;BYDAY=FRI',
comments => 'Friday alternative for New Year''s Day');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'NYD_MON',
repeat_interval => 'FREQ=YEARLY;BYDATE=0102;BYDAY=MON',
comments => 'Monday alternative for New Year''s Day');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'NewYearsDay',
repeat_interval => 'FREQ=YEARLY;BYDATE=0101;BYDAY=MON,TUE,WED,THU,FRI;'
|| 'INCLUDE=NYD_FRI,NYD_MON',
comments => 'New Year''s Day');
);
END;
/
2)创建一个计划,其中包含上面创建的所有计划。
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'FederalHolidays',
repeat_interval => 'NewYearsDay,MartinLutherKing,PresidentsDay,',
comments => 'Federal Holidays');
END;
3)创建一份工作,注意“EXCLUDE”和“BYSETPOS”选项
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'Run_Next_Day',
job_type => 'PLSQL_BLOCK',
job_action => 'begin Run_Next_Day; end; ',
repeat_interval => 'FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; byhour=14;byminute=30;bysecond=0; EXCLUDE=FederalHolidays; BYSETPOS=7',
enabled => TRUE,
comments => 'Skipping Holidays');
END;
/
答案 1 :(得分:1)
@XING谢谢你的帮助。我根据自己的需要修改了您的解决方案。
我的问题的答案是
元旦
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_NYD_MON',
repeat_interval => 'FREQ=YEARLY;BYDATE=0101;BYDAY=MON',
comments => 'Monday alternative for New Year''s Day');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_NEW_YEAR_DAY',
repeat_interval => 'FREQ=YEARLY;BYDATE=0101;BYDAY=MON,TUE,WED,THU,FRI;'
|| 'INCLUDE=SCHD_NYD_MON',
comments => 'New Year''s Day');
END;
/
11月的第一天
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_FNOV_MON',
repeat_interval => 'FREQ=YEARLY;BYDATE=1101;BYDAY=MON',
comments => 'Monday alternative for First November');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_FIRST_NOVEMBER',
repeat_interval => 'FREQ=YEARLY;BYDATE=1101;BYDAY=MON,TUE,WED,THU,FRI;'
|| 'INCLUDE=SCHD_FNOV_MON',
comments => 'First November''s Day');
END;
/
联邦假期
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_HOLIDAYS',
repeat_interval => 'SCHD_NEW_YEAR_DAY,SCHD_FIRST_NOVEMBER',
comments => 'Federal Holidays');
END;
/
工作
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'Run_Next_Day',
job_type => 'PLSQL_BLOCK',
job_action => 'begin Run_Next_Day; end; ',
repeat_interval => 'FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI;
byhour=12;byminute=0;bysecond=0;
EXCLUDE=SCHD_HOLIDAYS; BYSETPOS=1',
enabled => TRUE,
comments => 'Skipping Holidays');
END;
/