PL/SQL通过循环删除表
当我们在提取数据时,有些表中的数据量特别大,如果再和另一个数据量大的表关联,不仅仅会消耗大量的资源,而且会占用我们大量的时间,这时候我们就会通过建立临时表,先从A表中提取出我们需要的数据,然后和B表关联,随着表越来越多,我们就需要进行维护删除了,如果一个个的删不仅麻烦还容易出错(想想你要drop 999个表),那么如何批量的删除呢,请看下方:
declare
cursor droptab is select table_name from (select t.table_name from user_tables t
where t.table_name like '%模糊查找表名%' );
begin
for dt in droptab loop
execute immediate 'drop table ' || dt.table_name;
end loop;
dbms_output.put_line('执行成功');
commit;
exception
when others then
dbms_output.put_line('执行出错' || sqlerrm);
rollback;
end;