您好,欢迎访问一九零五行业门户网

Oracle 多进程更新同一个表

因业务表在数据转换时,相应的标识符没有加上,故需多进程对同一张表操作,从而提高更新的效率。
因业务表在数据转换时,,相应的标识符没有加上,故需多进程对同一张表操作,从而提高更新的效率。
1、写好相应的存储过程:
create or replace procedure proc_update_xxx(being_num in integer,end_num in integer) is
 cursor c_table is
  select * from(
  select a.*, row_number() over(order by rowid) rk from table a
) where rk>being_num and rk
  v_table c_table%rowtype;
i integer;
  begin
  i := 0;
...
end;
2、多进程:使用dbms_scheduler.create_job实现
相应的存储过程如下:(也可以改写成匿名快来执行)
create or replace procedure proc_job_xxx is
v_max_thread integer;
str_job varchar2(500);
prm_had_update varchar2(20);
prm_had_update_1 integer;
prm_had_update_2 integer;
begin
    v_max_thread := 8;--进程数目
select v_had_num into prm_had_update  from tmemp_hadupdate_lcm_20140124;--已更新的数目
for x in 0 .. v_max_thread-1 loop
          prm_had_update_1 := prm_had_update +x*100;
                              prm_had_update_2 := prm_had_update +(x+1)*100;
    str_job := 'declare
begin
      proc_update_xxx('''||  prm_had_update_1 ||''' ,''' ||prm_had_update_2  ||''' );
      end;';
      dbms_scheduler.create_job(job_name => 'update_xxx_thread_' || x,
                                job_type => 'plsql_block',
                                job_action => str_job,
                                enabled => false,
                                auto_drop => true,
                                comments => 'proc_update_xxx_' || x);
dbms_scheduler.enable(name => 'update_xxxx_thread_' || x);
end loop;        update tmemp_hadupdate_lcm_20140124
            set v_had_num  =prm_had_update + 100 *v_max_thread;
            commit;
end;
其它类似信息

推荐信息