刪除用戶所有表裏面的數據

declare

  plsql_block varchar2(512);

begin

  --at first,we should disable all constraint of tables

  for t in (select table_name, constraint_name
              from user_constraints
             where constraint_type = 'R') loop
  
    plsql_block := 'alter table ' || t.table_name || ' disable constraint ' ||
                   t.constraint_name;
  
    execute immediate plsql_block;
  
  end loop;

  --second,truncate table.if table has triger,wu must use truncate.

  for t in (select table_name from user_tables) loop
  
    execute immediate 'truncate table ' || t.table_name;
  
  end loop;

  --at last,we enable all constrait of tables

  for t in (select table_name, constraint_name
              from user_constraints
             where constraint_type = 'R') loop
  
    plsql_block := 'alter table ' || t.table_name || ' enable constraint ' ||
                   t.constraint_name;
  
    execute immediate plsql_block;
  
  end loop;

end;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章