开发者

Writing a query to kill a user session

开发者 https://www.devze.com 2023-01-15 06:11 出处:网络
I have to write a query which should do the following task select SID from v$session where username = \'some user\'

I have to write a query which should do the following task

select SID from v$session where username = 'some user'

and if there is any SID by that particular username then kill that SID using the command below :

alter system kill session 'sid';

What I have wrtten currently is the following :

alter system kill session
    where sid = select sid from v开发者_Go百科$session where username = 'some user'

This query fails when there is no particular sid by that username

The query has to be such that there is no usage of curly braces '{' or '}'

And the query should be just a single line query, no multiple line queries.

The DB is ORACLE10g

Any suggestions??


What I usually do is:

select 'alter system kill session '''||sid||','||serial#||''';'
from v$session
where username = 'someuser';

This will return results like:

alter system kill session '11,222';
alter system kill session '22,444';

I then just copy and paste the result I want to execute.

No curly braces (how could there be any?), but I'm not sure it meets your one-line rule.

0

精彩评论

暂无评论...
验证码 换一张
取 消