Oracle 开发篇+批量停止并删除JOB(lightweight)

说明:本文为面向PL/SQL开发初学者的指导手册
标签:PL/SQL、批量停止JOB、LIGHTWEIGHT、游标、匿名块
易学:文中删去了不需要的多余部分,让初学者一目了然一学就会
温馨提示:如果您发现本文哪里写的有问题或者有更好的写法请留言或私信我进行修改优化


set serveroutput on
set line 150
set pages 200
col error for a80

declare
  i          simple_integer := 1;
  j          simple_integer := 2000;
  s1         simple_integer := 0;
  s2         simple_integer := 0;
  v_job_name varchar2(50);
  flag       pls_integer;
  --cur job running
  cursor cur_jobs_run is
    select *
      from dba_scheduler_running_jobs r
     where r.OWNER = 'ZZT'
       and r.JOB_STYLE = 'LIGHTWEIGHT';
  re_cur_jobs_run cur_jobs_run%ROWTYPE;
  --cur job list
  cursor cur_jobs_list is
    select *
      from dba_scheduler_jobs j
     where j.owner = 'ZZT'
       and j.JOB_STYLE = 'LIGHTWEIGHT';
  re_cur_jobs_list cur_jobs_list%ROWTYPE;
begin
  --【stop jobs】
  dbms_output.put_line('***************<TOP>***************');
  for re_cur_jobs_run in cur_jobs_run loop
    v_job_name := re_cur_jobs_run.owner || '.' || re_cur_jobs_run.job_name;
    dbms_scheduler.stop_job(v_job_name);
    dbms_output.put_line('>>> job: ' || v_job_name || ' is stoped!');
    s1 := s1 + 1;
  end loop;
  dbms_output.put_line('// Total stoped <' || s1 ||
                       '> jobs, and no jobs running now !');
  --【drop jobs】
  open cur_jobs_list;
  loop
    fetch cur_jobs_list
      into re_cur_jobs_list;
    if cur_jobs_list%FOUND then
      v_job_name := re_cur_jobs_list.owner || '.' ||
                    re_cur_jobs_list.job_name;
      dbms_scheduler.drop_job(v_job_name, true);
      dbms_output.put_line('>>> job: ' || v_job_name || ' is droped!');
    else
      dbms_output.put_line('// Total droped <' || s1 ||
                           '> jobs, no more jobs exist or AUTO-DROPED !');
      exit when cur_jobs_list%NOTFOUND;
    end if;
    s2 := s2 + 1;
  end loop;
  close cur_jobs_list;
  dbms_output.put_line('***************<END>***************');
  --【exception】
exception
  when others then
    --close cur_jobs_run
    if cur_jobs_run%isopen then
      close cur_jobs_list;
      dbms_output.put_line('>>> error [cur_jobs_run]');
    end if;
    --close cur_jobs_list
    if cur_jobs_list%isopen then
      close cur_jobs_list;
      dbms_output.put_line('>>> error [cur_jobs_list]');
    end if;
end;
/

 


※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~

over

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值