使用PL/SQL快速删除用户下的所有表数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/long2010yu2010/article/details/22649621

使用PL/SQL快速删除用户下的所有表数据

在Oracle中如果要删除用户的表数据有多种的方法,这里可推荐一种比较快速的方法,能够删除用户下的所有表数据,通过plsql这个语言就可以快速的删除,代码如下所示:

declare
  cursor c_t is (select table_name from user_tables);--声明一个游标
  table_name user_tables.table_name%type;--声明一个表名的变量
begin 
  open c_t;
  loop—循环
       fetch c_t into table_name;
       exit when c_t%notfound;
       execute immediate 'delete from ' || table_name;--动态sql删除
  end loop;
  close c_t;
end;

在Oracle中,user_tables是一张字典表,存储了用户表的信息,我们通过游标可以获取到该字典表中存储的当前用户表的信息,然后循环删除每一张表里的数据。很简单的,这个在开发的过程中应该会经常遇到的。

猜你喜欢

转载自blog.csdn.net/long2010yu2010/article/details/22649621