Home > Database > Mysql Tutorial > body text

Oracle 多进程更新同一个表

WBOY
Release: 2016-06-07 17:35:03
Original
1294 people have browsed it

因业务表在数据转换时,相应的标识符没有加上,故需多进程对同一张表操作,从而提高更新的效率。

因业务表在数据转换时,,相应的标识符没有加上,故需多进程对同一张表操作,从而提高更新的效率。

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;

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template