ITeye博客

Oracle强制删除指定schema及相关的所有数据库对象

wanglei8 · 2012-05-23 13:24 · oracle · 数据库 · Markdown

创建一个drop_schema.sql文件,内容如下


set define on
set serveroutput on
connect / as sysdba

define schema = &1
-- Kill Session connecting to the schemas to be dropped
Declare
    Cursor c_session Is
    SELECT s.sid, s.serial#
      FROM gv$session s
      JOIN gv$process p ON p.addr = s.paddr
       AND p.inst_id = s.inst_id
     WHERE s.type != 'BACKGROUND'
       AND s.username = '&schema');
Begin
    For r_session In c_session Loop
        Execute Immediate 'ALTER SYSTEM KILL SESSION '''||r_session.sid||','||r_session.serial#||'''';
    End Loop;
End;
/
-- Drop schemas
Drop User &schema Cascade;

set define off
exit


授权


chmod +x drop_schema.sql

进入sqlplus环境,并执行该文件


$sqlplus /nolog
@drop_schema.sql

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。