Showing posts with label sqlplus. Show all posts
Showing posts with label sqlplus. Show all posts

Kill connections to an Oracle Schema


You can kill all connections by running the code below. Just Replace SCHEMA with your schema name.

declare str varchar2(100);
begin
for SES in (select sid,serial# from v$session where username='SCHEMA'  )
loop
str := 'alter system disconnect session '|| '''' || to_char(SES.sid) ||','||to_char(SES.serial#)||'''' || ' ' || 'immediate';
execute immediate str;
end loop;
end;


To kill a single connection, first find the connection by running:

select * from v$session;

Then run:

alter system kill session 'sid,serial#';

where sid and serial# are extracted from your first query of v$session above.

How to run sqlplus


To run sqlplus you need 3 env var set. Set them as follows if they are not set already. ( you can check if they are set by doing "echo $ORACLE_SID" for example to see if your SID is set. )

export ORACLE_HOME=<your Oracle Home>
export PATH=%ORACLE_HOME%\bin;%PATH%
export ORACLE_SID=<your SID>

Then run the following at the command line to start sqlplus.
sqlplus /nolog

This starts sqlplus with no user logged in.