Bootstrap

批量禁用和启用外键、触发器

SET SERVEROUTPUT ON SIZE 100000                                                                                                                         
BEGIN                                                                                                                                                   
for c in (select 'alter table "'||t.owner||'".'||t.table_name ||' disable constraint '||t.constraint_name as v_sql
from dba_constraints t where t.constraint_type = 'R' and owner  in ('CCOD','RECORD','UCDS')
) loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);                                                                                                                          
begin                                                                                                                                                   
 EXECUTE IMMEDIATE c.v_sql;                                                                                                                             
 exception when others then                                                                                                                             
 dbms_output.put_line(sqlerrm);                                                                                                                         
 end;                                                                                                                                                   
end loop;                                                                                                                                               
for c in (select 'alter trigger "' || t.owner || '".' || t.trigger_name ||
       ' disable' as v_sql
  from dba_triggers t
 where owner  in ('CCOD','RECORD','UCDS')) loop                                          
 dbms_output.put_line(c.v_sql);                                                                                                                         
 begin                                                                                                                                                  
 execute immediate c.v_sql;                                                                                                                             
exception when others then                                                                                                                              
 dbms_output.put_line(sqlerrm);                                                                                                                         
 end;                                                                                                                                                   
end loop;                                                                                                                                               
end;                                                                                                                                                    
/                                                                                                                                                       
                                                                                                                                                        
--启用脚本                                                                                                                                              
SET SERVEROUTPUT ON SIZE 100000                                                                                                                         
BEGIN                                                                                                                                                   
for c in (select 'alter table "'||t.owner||'".'||t.table_name ||' enable constraint '||t.constraint_name as v_sql
from dba_constraints t where t.constraint_type = 'R' and owner  in ('CCOD','RECORD','UCDS')) loop 
DBMS_OUTPUT.PUT_LINE(C.V_SQL);                                                                                                                          
begin                                                                                                                                                   
 EXECUTE IMMEDIATE c.v_sql;                                                                                                                             
 exception when others then                                                                                                                             
 dbms_output.put_line(sqlerrm);                                                                                                                         
 end;                                                                                                                                                   
end loop;                                                                                                                                               
for c in (select 'alter trigger "' || t.owner || '".' || t.trigger_name ||
       ' enable' as v_sql
  from dba_triggers t
 where owner  in ('CCOD','RECORD','UCDS')) loop                                           
 dbms_output.put_line(c.v_sql);                                                                                                                         
 begin                                                                                                                                                  
 execute immediate c.v_sql;                                                                                                                             
exception when others then                                                                                                                              
 dbms_output.put_line(sqlerrm);                                                                                                                         
 end;                                                                                                                                                   
end loop;                                                                                                                                               
end;                                                                                                                                                    
/                                                                                                                                                       

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30592920/viewspace-2143908/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30592920/viewspace-2143908/

;