Oracle并行调用存储过程

Oracle并行调用存储过程

网上很少看到有对Oracle并行的介绍,下面通过Oracle中的dbms_job包实现存储过程的并行调用:

create table a(id number);
create table b(id number);

create or replace procedure pro_a is
begin
  for i in  1 .. 10 loop
    insert into a values (i);
    dbms_lock.sleep(5);
    commit;
  end loop;
end;
/

create or replace procedure pro_b(v_num in number default 10) is
begin
  for i in reverse 1 .. v_num loop
    insert into b values (10+i);
    dbms_lock.sleep(5);
    commit;
  end loop;
end;
/

-- 串行
begin
  pro_a;
  pro_b;
end;
/

CREATE OR REPLACE PROCEDURE pro_job(pro_name in varchar2) as
  v_job binary_integer;
begin
  -- 通过一个job一个存储过程来实现并行调用
  dbms_job.submit(v_job,pro_name);
  dbms_output.put_line(v_job);
  commit;
end;
/

-- 并行执行存储过程
begin
  pro_job('pro_a;');
  pro_job('pro_b(''7'');');
end;
/

--查询是否并行
select * from a;
select * from b;

--删除重新实验
--delete from a;
--delete from b;
--commit;

--查询job的运行情况
select * from user_jobs;
select * from dba_jobs_running;

也可以使用DBMS_SCHEDULER来实现,可参考
https://docs.oracle.com/cd/E11882_01/server.112/e25494/appendix_a.htm#ADMIN11002

你可能感兴趣的:(oracle)