• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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

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;  

posted on 2018-04-08 09:45  gisai  阅读(151)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3