清空所有表:

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

相关文章:

  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-07-01
相关资源
相似解决方案