我要批量处理几个表结构,增加一个字段,并更新该字段值,
功能:给XXXX表增加字段NEWCLUM,并更新存在于YYYY中的记录的该字段。我的处理:
create or replace procedure A (mon char) 
is                                                                                                  
  v_sql   varchar2(1000);                                                                           
begin                                                                                               
  for vrec in (select TABLE_NAME from all_tables where LENGTH(TABLE_NAME)=23                        
    and owner='XXXX' AND upper(substr(TABLE_NAME,1,4))='XXXX' and substr(TABLE_NAME,5,1)=mon) loop                                                                                       
     v_sql := 'ALTER TABLE '||vrec.TABLE_NAME||' ADD (NEWCLUM CHAR(1))';                                                                                                
     execute immediate v_sql;                                                                       
                                                                                                    
     v_sql:='update ' || vrec.TABLE_NAME || ' a set NEWCOLUM=''1'' where a.rowid in          
     (select distinct a.rowid from YYYY b where a.a1 = b.b1 and a.a2 = b.b2                                                                                        
        and a.a3 = b.b3 and a.a4 = b.b4)';                              
                                                                                                    
    /*v_sql:='update ' || vrec.TABLE_NAME || ' a set secondflag=''1'' where exists                  
     (select 1 from T_AC_SECONDACCTSHT_A b where a.acctid = b.acctid and a.userid = b.userid        
        and a.acctitem = b.acctitem and a.billcyclid = b.billcyclid)';*/                            
     execute immediate v_sql;                                                                       
     commit;                                                                                        
  end loop;                                                                                         
  commit;                                                                                           
exception                                                                                           
  when others then                                                                                       rollback;                                                                                           raise;                                                                                         
end;
可是执行起来效率不高,是不是sql写的效率比较低,大家看看有其他实现方法?