技术分享 数据库 ORACLE 查看内容

Oracle sql*plus 删除当前用户的所有对象

老高 | 发布于 2016-10-19 16:12| 浏览()| 评论() | 收藏() | 点赞() | 打印

--Oracle sql*plus - 删除当前用户的所有对象

--@.sql脚本 - langx转载整理

--测试环境:Oracle9i (Windwos XP)

--唯一注意的是下面的f:\dropobj.sql 为操作的.sql;

--你的电脑没有F盘,请换为D或者E其他存在的盘符

--用于删除当前用户的所有对象

--This sql-file is used for dropping all objects in current user;

set heading off;   
set feedback off;   
spool D:\dropobjall.sql;   
prompt --Drop constraint   
select 'alter table '||table_name||' drop constraint '||constraint_name||' ;' from user_constraints where constraint_type='R';   
prompt --Drop tables   
select 'drop table '||table_name ||';' from user_tables;    

prompt --Drop view   
select 'drop view ' ||view_name||';' from user_views;   

prompt --Drop sequence   
select 'drop sequence ' ||sequence_name||';' from user_sequences;    

prompt --Drop function   
select 'drop function ' ||object_name||';'  from user_objects  where object_type='FUNCTION';   

prompt --Drop procedure   
select 'drop procedure '||object_name||';' from user_objects  where object_type='PROCEDURE';   

prompt --Drop package   
prompt --Drop package body   
select 'drop package '|| object_name||';' from user_objects  where object_type='PACKAGE';   

prompt --Drop database link   
select 'drop database link '|| object_name||';' from user_objects  where object_type='DATABASE LINK';   
    
spool off;   
set heading on;   
set feedback on;

@@f:\dropobj.sql;

host del f:\dropobj.sql;

--Dropping all objects in current user is done;

--在SQL*PLUS 将这整段作为.sql导入或者直接复制黏贴,按F5执行,完成。


上一篇: Oracle常用管理命令
下一篇: Oracle导库脚本

发表评论(对文章涉及的知识点还有疑问,可以在这里留言,老高看到后会及时回复的。)

表情