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?