Patrick's 데이터 세상

나눠서 입력하는 insert pl/sql문 본문

Programming/Oracle

나눠서 입력하는 insert pl/sql문

patrick610 2021. 1. 29. 11:47
반응형
SMALL

 

 

 

한번에 많은 건수를 insert하면 속도 문제가 있고, rollback 세그먼트에 대기하고 있는 건수가 너무 많아서

1000건 씩 나눠서 입력하는 insert pl/sql문

 

 

begin
       declare
           r int := 0;
       cursor c1 is
           select /*+ PARALLEL(a,4) */ rowid, 컬럼, 키값  from 인서트정보테이블;
       begin
           for x in c1
           loop
                 update 테이블  a set  update대상컬럼    = substr(x.update입력컬럼, 1, 6)
                 where 키값 =x.키값;
                 --where  x.rowid=rowid;  -- 같은 테이블 업데이트인 경우 rowid 로..
               r := r + 1;
               if mod(r, 1000) = 1 then
                  commit;
               end if;
           end loop;
               commit;
           exception when others then null;
      close c1;
       end;
end;
/ 

 

 

 

반응형
LIST
Comments