如何安排需要在Oracle中每小时运行的作业?
此作业应该能够执行3个Oracle DB select语句。
答案 0 :(得分:1)
这是一个简单的演示,可以帮助您入门
三张桌子
SQL> create table t1 as select * from user_objects;
Table created.
SQL> create table t2 as select * from user_objects where object_id > 100;
Table created.
SQL> create table t3 as select * from all_objects where owner = 'SCOTT';
Table created.
现在我们编写一些简单的PLSQL来刷新它们
SQL> begin
2 delete t1;
3 delete t2;
4 delete t3;
5 insert into t1 select * from user_objects;
6 insert into t2 select * from user_objects where object_id > 100;
7 insert into t3 select * from all_objects where owner = 'SCOTT';
8 commit;
9 end;
10 /
PL/SQL procedure successfully completed.
如果我们对此工作感到高兴,我们只需将调度程序作业包装成每小时运行一次
SQL> declare
2 l_anon_block varchar2(500) :=
3 q'{begin
4 delete t1;
5 delete t2;
6 delete t3;
7 insert into t1 select * from user_objects;
8 insert into t2 select * from user_objects where object_id > 100;
9 insert into t3 select * from all_objects where owner = 'SCOTT';
10 commit;
11 end;}';
12 begin
13 dbms_scheduler.create_job (
14 job_name => 'MY_REFRESH_JOB',
15 job_type => 'PLSQL_BLOCK',
16 job_action => l_anon_block,
17 start_date => sysdate,
18 repeat_interval => 'FREQ=HOURLY',
19 enabled => true,
20 comments => 'Hourly Refresh');
21 end;
22 /
PL/SQL procedure successfully completed.