Oracle清空当前用户下所有表的数据

来源:互联网 发布:c语言温度转换 编辑:程序博客网 时间:2024/05/19 09:02
转载自http://blog.csdn.net/zeng_lingfan/article/details/6744766
[sql] view plaincopy
  1. /**   
  2.    将所有的 table 清空(可回滚)  
  3. **/  
  4. declare  
  5.   -- 指向所有 table 的游标  
  6.   cursor c_t is   
  7.     select table_name  
  8.     from user_tables;  
  9.     
  10.   table_name user_tables.table_name%type;  
  11. begin  
  12.   open c_t;  
  13.   loop   
  14.        fetch c_t into table_name;   
  15.        exit when c_t%notfound;  
  16.          
  17.        -- 用 delete 而不用 truncate 是为了能户用户回滚,减少误操作  
  18.        execute immediate 'delete from ' || table_name;  
  19.   end loop;  
  20.   close c_t;  
  21. end;  
0 0
原创粉丝点击