we have this query:
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
I need to kill all sessions which have the same SQL ID
I’m not sure how to connect things together, but I have this so far:
for rec in (SELECT se.sid,ss.serial#
FROM v$session ss, v$sesstat se, v$statname sn
WHERE se.statistic# = sn.statistic#
AND name like '%CPU used by this session%'
AND se.sid = ss.sid
AND ss.status = 'ACTIVE'
AND ss.username is not null
AND ss.sql_id ='f7frew3erwe'
ORDER BY value ASC) loop
ALTER SYSTEM KILL SESSION 'rec.sid,rec.serial#' IMMEDIATE; //this is the tricky part!
end loop;
Any suggestions?
The question is similar to How can I kill all sessions connecting to my oracle database?, though for not for all sessions.
You need to use
execute immediatein order to alter the system in a PL/SQL block:I query your need to use all the additional system tables. Something like the following query may suffice if all you want to kill is a specific
SQL_ID: