Oacle 일괄 삭제 방법

Oacle 에서 빅 데 이 터 를 삭제 할 때 undo 에 큰 스트레스 를 주 고 잠 금 도 자주 발생 하기 때문에 분할 제출 방식 을 자주 사용 합 니 다.
다음 저장 프로시저 전환:http://www.eygle.com/archives/2005/02/ecioioaeoeeeioe.html
create or replace procedure deleteTab
(                                                                                                
  p_TableName    in    varchar2,    -- The TableName which you want to delete from               
  p_Condition    in    varchar2 default '1=1',    -- Delete condition, such as "id>=100000"                    
  p_Count        in    varchar2 default '10000'    -- Commit after delete How many records                      
)                                                                                                
as                                                                                               
 pragma autonomous_transaction;                                                                  
 n_delete number:=0;                                                                             
begin                                                                                            
 while 1=1 loop                                                                                  
   EXECUTE IMMEDIATE                                                                             
     'delete from '||p_TableName||' where '||p_Condition||' and rownum <= :rn'                   
   USING p_Count;                                                                                
   if SQL%NOTFOUND then                                                                          
   exit;                                                                                         
   else                                                                                          
        n_delete:=n_delete + SQL%ROWCOUNT;                                                       
   end if;                                                                                       
   commit;                                                                                       
 end loop;                                                                                       
 commit;                                                                                         
 DBMS_OUTPUT.PUT_LINE('Finished!');                                                              
 DBMS_OUTPUT.PUT_LINE('Totally '||to_char(n_delete)||' records deleted!');                       
end;                                                                                             
/                           

 
execute trswcmnew.deletetab('T1','id>20','2000');

좋은 웹페이지 즐겨찾기