---
title: "oracle 删除某个用户下的所有对象"
author: "panfuy"
date: "2011-11-11T11:32:28Z"
tags: ["oracle 删除某个用户下的所有对象"]
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2011-11-11T11:33:47Z"
id: 1252271
url: "https://panfuy.iteye.com/blog/1252271"
---

先存放好dropobj.sql 文件 然后登录需要删除的用户

 

删除前最好备份一下：（备份是在cmd中进行的） 

 

C:\\Users\\panfu&gt;exp file=d:\\expall.dmp log=expall.log **full=y**

 

Export: Release 10.2.0.1.0 - Production on 星期五 11月 11 11:27:57 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

 

用户名: [/@DBName]() as sysdba

 

 

执行一下命令:

SQL&gt; show user;

  查看是否是当前需要删除的用户

    （用sqlplus登录如果密码错了会登录到sys用户，一定要注意**不要删错用户**，不然后悔晚矣~~）

SQL&gt;@D:\\dropobj.sql

 

 等待执行完成后，

 

SQL&gt;@D:\\dropobjall.sql

 

删除完成~~

 

 

复制以下内容存放在d:\\dropobj.sql 中:  
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;