-
Notifications
You must be signed in to change notification settings - Fork 24
/
kill_my_session.sql
68 lines (52 loc) · 1.5 KB
/
kill_my_session.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
create or replace procedure sys.kill_my_session (
sid_ in number,
serial in number
) as
--
-- Found at
-- http://dba-blogs.blogspot.com/2013/09/kill-my-session.html
-- slightly adapted by me
--
this_ses_user varchar2(32);
other_ses_user varchar2(32);
this_machine varchar2(32);
other_machine varchar2(32);
instance number;
begin
this_ses_user := sys_context('userenv', 'session_user');
this_machine := sys_context('userenv', 'host' );
begin
select
username,
inst_id,
machine
into
other_ses_user,
instance,
other_machine
from
gv$session
where
sid=sid_ and
serial#= serial;
exception when no_data_found then
dbms_output.put_line('no session found for ' || sid_ || ',' || serial);
return;
end;
if this_ses_user = other_ses_user and this_machine = other_machine then
declare
stmt varchar2(200);
begin
stmt := 'alter system kill session ''' || sid_ || ',' || serial || ',@' || instance || '''';
execute immediate stmt;
dbms_output.put_line('successful: ' || stmt);
exception when others then
dbms_output.put_line(stmt || ' threw ' || sqlerrm);
end;
else
dbms_output.put_line(q'[cannot kill another user's session]');
end if;
end;
/
show err
grant execute on kill_my_session to public;