To Kill the sessions:
DECLARE -- declare variables
CURSOR c1 IS
select sid, serial# from v$session
where username='ADPE'; -- declare cursor
-- declare record variable that represents a row fetched
kill_it c1%ROWTYPE; -- declare variable with %ROWTYPE attribute
BEGIN
-- open the explicit cursor c1
OPEN c1;
LOOP
FETCH c1 INTO kill_it; -- retrieve record
EXIT WHEN c1%NOTFOUND;
BEGIN
EXECUTE IMMEDIATE 'alter system kill session '''||
kill_it.sid||', '||kill_it.serial#||'''';
END;
END LOOP;
CLOSE c1;
END;
To disconnect the sessions:
DECLARE -- declare variables
CURSOR c1 IS
select sid, serial# from v$session
where username='SSS'; -- declare cursor
-- declare record variable that represents a row fetched
kill_it c1%ROWTYPE; -- declare variable with %ROWTYPE attribute
BEGIN
-- open the explicit cursor c1
OPEN c1;
LOOP
FETCH c1 INTO kill_it; -- retrieve record
EXIT WHEN c1%NOTFOUND;
BEGIN
EXECUTE IMMEDIATE 'alter system disconnect session '''||
kill_it.sid||', '||kill_it.serial#||'''immediate';
END;
END LOOP;
CLOSE c1;
END;
Please note that disconnect is more powerful than kill.
No comments:
Post a Comment