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

创建一个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


你可能感兴趣的:(oracle,drop schema)