1億件以上のデータをバックアップし、履歴表をバックアップし、正表データ案を削除


  :
                ,        

  
   1                     ,        
   2            ,             ,        
             (         ,    mod        ,       ,
                  ).

      
   1:     
     create tabel task_chl_statuscd1100107 as select contact_task_chl_id from task_chl
   2:         
   3:      (              ),          
    create or replace procedure toTaskChl(i_size in number) is

  v_insertSql varchar2(500);
  v_tableDate varchar2(500);

begin
    --     mod       ,              ,     ,     
    --             
  for r in (select *
              from task_chl_statuscd1100107
             where mod(contact_task_chl_id, 1) = i_size
               and rownum < 5001) loop
  
    select to_char(a.create_Date, 'yyyyMM')
      into v_tableDate
      from contact_task_chl a
     where a.contact_task_chl_id = r.contact_task_chl_id;
  
    v_insertSql := 'insert into contact_task_chl_' || v_tableDate ||
                   ' select * from contact_task_chl where contact_task_chl_id = ' ||
                   r.contact_task_chl_id;
    EXECUTE IMMEDIATE v_insertSql;
    delete from contact_task_chl
     where contact_task_chl_id = r.contact_task_chl_id;
    delete from task_chl_statuscd1100107
     where contact_task_chl_id = r.contact_task_chl_id;
  end loop;
  --dbms_output.put_line(v_insertSql);
  commit;
end toTaskChl;