zoukankan      html  css  js  c++  java
  • ORACLE小工具:存储过程清空所有表或使所有触发器失效

    清空所有表:

    CREATE OR REPLACE PROCEDURE CLEAN_TABLES as
      v_tablename varchar2(256);
      cursor cur_tablename is
        select object_name from user_objects where object_type = 'TABLE';
    begin
      open cur_tablename;
      loop
        fetch cur_tablename
          into v_tablename;
        exit when cur_tablename%notfound;
        execute immediate 'delete from ' || v_tablename || '';
      end loop;
      close cur_tablename;
    end CLEAN_TABLES;

    运行:

    begin
      CLEAN_TABLES();
    end;

    失效所有触发器:

    CREATE OR REPLACE PROCEDURE DISABLE_TRIGGER as
      v_sql varchar2(100);
      v_ref sys_refcursor;
    begin
      for v_ref in (select object_name
                      from user_objects
                     where object_type = 'TRIGGER') loop
        v_sql := 'alter trigger ' || v_ref.object_name || 'disable';
        execute immediate v_sql;
        dbms_output.put_line(v_sql);
      end loop;
    exception
      when others then
        dbms_output.put_line(SQLCODE || '---' || SQLERRM);
    end DISABLE_TRIGGER;

    生效所有触发器:

    CREATE OR REPLACE PROCEDURE ENABLE_TRIGGER as
      v_sql varchar2(100);
      v_ref sys_refcursor;
    begin
      for v_ref in (select object_name
                      from user_objects
                     where object_type = 'TRIGGER') loop
        v_sql := 'alter trigger ' || v_ref.object_name || 'enable';
        execute immediate v_sql;
        dbms_output.put_line(v_sql);
      end loop;
    exception
      when others then
        dbms_output.put_line(SQLCODE || '---' || SQLERRM);
    end ENABLE_TRIGGER;

    that's it

  • 相关阅读:
    网络编程-Python的socket库
    Python -用虚拟环境保存库文件
    Python --文件的读写
    VIM--常用操作
    libpcap -学习1
    Python -装饰器
    C++ 关于map,function的简单应用
    UVAlive 3635 (13.08.23)
    C语言中的整型提升(integral promotion)
    [置顶] 从一位数组中提取最小k个元素
  • 原文地址:https://www.cnblogs.com/garfieldcgf/p/5992980.html
Copyright © 2011-2022 走看看