ITPub博客

首页 > 数据库 > Oracle > 批量禁用和启用外键、触发器

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

原创 Oracle 作者:正月十七 时间:2017-08-21 16:57:31 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/30592920/viewspace-2143908/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2015-11-27

  • 博文量
    21
  • 访问量
    19449