kill all session a user without user current session in oracle
conn hr/hr@orcl
BEGIN
FOR r IN (select a.sid,a.serial# from v$session a
where a.username = 'HR'
and a.sid||a.serial# not in (SELECT b.SID||b.SERIAL#
FROM GV$SESSION b
WHERE b.AUDSID = Sys_Context('USERENV', 'SESSIONID')
AND b.SID = Sys_Context('USERENV', 'SID')
and a.sid=b.sid and a.serial#=b.serial#))
LOOP
EXECUTE IMMEDIATE 'alter system kill session ''' || r.sid || ',' || r.serial# || '''';
END LOOP;
END;
without err
kill all session a user without user current session in oracle & err below
BEGIN
FOR r IN (select sid,serial# from v$session where username = 'HR')
LOOP
EXECUTE IMMEDIATE 'alter system kill session ''' || r.sid || ',' || r.serial# || '''';
END LOOP;
END;
ERROR at line 1:
ORA-00027: cannot kill current session
ORA-06512: at line 7
/*
begin
for sessions in ( select sid
, serial#
from v$session
where username = 'user_to_kill_sessions')
loop
execute immediate 'alter system kill session '''||sessions.sid||','|sessions.serial#||'''';
end loop;
end;
*/
No comments:
Post a Comment