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

  • 相关阅读:
    千里之行,始于足下
    Asp.Net构架(Http请求处理流程)
    c# MVC5(二) MVC与IOC结合
    c# MVC5(一) 初步认识以及新建mvc
    使用C#创建Windows服务
    Cron Expressions——Cron 表达式(QuartZ调度时间配置)
    定时调度之Quartz
    ORM之EF初识
    Redis原理及使用
    为什么使用 Redis 及其产品定位
  • 原文地址:https://www.cnblogs.com/garfieldcgf/p/5992980.html
Copyright © 2011-2022 走看看