oracle 刪除某個用戶下的所有對象


先存放好dropobj.sql 文件 然后登錄需要刪除的用戶

 

刪除前最好備份一下:(備份是在cmd中進行的) 

 

C:\Users\panfu>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> show user;

  查看是否是當前需要刪除的用戶

    (用sqlplus登錄如果密碼錯了會登錄到sys用戶,一定要注意不要刪錯用戶,不然后悔晚矣~~)


SQL>@D:\dropobj.sql

 

 等待執行完成后,

 

SQL>@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;  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM