1.首先创建节假日表。
-- Create table
create tableFESTIVAL
(
FESTIVAL_DAY DATE not null,
FE_LAG NUMBER default 0
)
tablespace CCRS_TP
pctfree 10
initrans 1
maxtrans255
storage
(
initial 64
next1
minextents 1
maxextents unlimited
);
-- Add comments tothe table
comment on tableFESTIVAL
is '节假日存储表';
-- Add comments tothe columns
comment on columnFESTIVAL.FESTIVAL_DAY
is '节日日期';
comment on columnFESTIVAL.FE_LAG
is '当该值为1时,是上班的周日或者周六日期';
2.获取放假通知。并将节日日期录入,并将倒休日期也一并录入。
但注意FE_LOG字段,倒休日对应1.即上班执行。以2018年为例子。录入信息情况如下:
3.创建执行存储过程
autoetl_day
脚本如下:
create or replaceprocedure autoetl_day (indate in date)
is --输入参数
flg number;
mlg number;
begin
--如果是周六日被节假日调休的情况,且该日期是周六或者周日
select count(1) into flg from FESTIVAL f where f.festival_day=indate and f.fe_lag=1;
select count(1) into mlg from FESTIVAL f1 where f1.festival_day=indate and f1.fe_lag=0;
if (flg)=1 and (to_char(indate,'d') ='1' or to_char(indate,'d') ='7')
then
dbms_output.put_line(' 假日调休抽取'||indate);
insert into N_ETL_LOG(ETL_LOGCONTENT) values('调休日抽取'||to_char(indate,'yyyymmdd')||'抽取完成');
elseif --如果是节日情况
mlg<>0
then dbms_output.put_line('节日不抽取'||indate);
elseif (to_char(indate,'d') ='1' or to_char(indate,'d') ='7')
then dbms_output.put_line(' 周六日不抽取'||indate);
else
dbms_output.put_line(' 工作日抽取'||indate);
insert into N_ETL_LOG(ETL_LOGCONTENT)values('工作日'||to_char(indate,'yyyymmdd')||'抽取完成');
end if;
end if;
end if;
commit;
end;
4.创建自动执行job
begin
sys.dbms_job.submit(job => :job,
what => 'autoetl_day(trunc(sysdate));,
next_date =>to_date('18-01-2018 05:40:00', 'dd-mm-yyyy hh24:mi:ss'), --执行间隔是每天5:40执行
interval =>'TRUNC(sysdate + 1) +(5*60+40)/(24*60)');
commit;
end;