I'm using PL/SQL Developer. Now I need to kill all sessions with a specific status(e.g. INACTIVE) in my oracle database by a single click. Currently I'm killing session one by one. My current strategy is
first GOTO sessions
And then click right button of mouse and select kill row by row:
I've tried both Shift and CTR key to select multiple row at a time but they are failed to select multiple rows.
Killing inactive sessions can be done in 3 clicks with a custom template.
(If you really need a one-click solution you'll probably need to create a custom plugin using Delphi. But that would take a lot of work.)
Once you create and get used to template it will only take a second to run one. First, go to the Templates window, usually in the bottom-left-hand side of the screen. Right-click on the background and select "New Template...". Enter a name for the template.
Now enter this text. It's a PL/SQL block that will kill all inactive sessions.
begin
for sessions_to_kill in
(
select 'alter system kill session '''||sid||','||serial#||',@'||inst_id||''' immediate' v_sql
from gv$session
where status = 'INACTIVE'
--Can't kill your current session.
and not (sid = sys_context('userenv', 'sid') and inst_id = sys_context('userenv', 'instance'))
) loop
execute immediate sessions_to_kill.v_sql;
end loop;
end;
To call the template, right-click somewhere in a SQL window, select "Insert Template" and the name. Run the PL/SQL block after it appears in the SQL window.