删除当前数据库所有的表 过程

来源:互联网 发布:一年php工资7千 编辑:程序博客网 时间:2024/05/17 07:47
create or replace procedure P_DROP_ALL_TABLE  
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;  
阅读全文
0 0