sql实现节假日不执行脚本

  

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'),  --执行间隔是每天540执行

                     interval =>'TRUNC(sysdate + 1) +(5*60+40)/(24*60)');

  commit;

end;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值