Oracle存储过程-删除所有的表

删除所有表的存储过程.

 

--删除所有表的存储过程;  
create or replace procedure PROC_DROPTABLE_All
as 
  --引用user_tables表中的tableName的类型;
  tableName user_tables.table_name%type;  
  type ty is record(table_name varchar2(30));
  --定义ref类型游标;-强类型
  type ref_type is ref cursor return ty;
  ref_t ref_type;
  --定义变量存储数量;
  mycount number(10);
  begin
    --打开游标;
    open ref_t for select table_name from user_tables;
         loop
             --从游标中获取一条记录,放入变量中;
             fetch ref_t into tableName;
                    SELECT COUNT(*) INTO mycount FROM user_tables WHERE TABLE_NAME = tableName;
                    if mycount>0 then
                       execute immediate 'DROP TABLE '||tableName || ' CASCADE CONSTRAINT ';
                    end if;
             exit when ref_t%notfound;  --退出;
         end loop;
     close ref_t;    
  end;
/

 

你可能感兴趣的:(oracle存储过程)