使用select语句解释涉及for循环的查询,并包括作业的运行

时间:2014-09-22 10:04:19

标签: oracle plsql

begin
for i in (select job from user_jobs where job=3309 and what like '%LEDGER_REPORT%')
loop
dbms_job.run(i.job);
end loop;
end;
/
commit;
begin
for i in (select job from user_jobs where job=3309 and what like '%LEDGER_REPORT%')
loop
dbms_job.broken(i.job,TRUE);
end loop;
end;
/
commit;

有人可以解释这是如何工作的吗?我是新手,所以我期待一个像我这样的初学者很容易理解的解释。

1 个答案:

答案 0 :(得分:0)

--start of the anon block
begin
-- selecting the rows that match this query (will likely only ever be one)
for i in (select job from user_jobs where job=3309 and what like '%LEDGER_REPORT%')
-- now we have 'i' which is a table record type, with 'job' as the only column/value
loop
-- for each record found, do dbms_job.run(). Pass in the value from our FOR loop
dbms_job.run(i.job);
end loop;
end;
/
commit;
-- commit makes sure the job is running
begin
-- same as above...
for i in (select job from user_jobs where job=3309 and what like '%LEDGER_REPORT%')
loop
-- now we set the job status to BROKEN, which means it won't be run again unless manually called
dbms_job.broken(i.job,TRUE);
end loop;
end;
/
commit;

它可以使用一些优化,一种非常圆润的做事方式,但确实如此。随意请求任何其他说明。 dbms_job过程是Oracle打包过程,您可以在线找到有关它们的更多详细信息。