说明:本文为面向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