how to kill a session from a form????

hello oracle masters,
i'm trying to kill session from inside a form.  i'm currently using developer 6i ver with 8i database.  using a select in the sys.v$session, i know the pid and session no.  with this info, i need to do an 'alter system kill session...' statement but do not exactly know how.

do i just create a button and with the 'when button pushed trigger' type the command?  i'd really appreciate any comments....

Who is Participating?
mahbub007Connect With a Mentor Commented:
dear zandyl,
           u can use a button in the form for killing the session.
the code will be like this:


cursor sess_cur
is select sid,serial#
from v$session
where username = 'ur specific user for which u want to kill the session'-- you may avoid this clause
                 --  to kill all the user's sessions.
and / or status = 'ACTIVE'/'INACTIVE';
                        --use this cluse to kill the
                        --sessions which are inactive
                       --or active,or u can avoid this    
                       --caluse to kill all the session

v_sid number;
v_serial number;
v_st varchar2(100);
open sess_cur;  --open the cursor;

   fetch sess_cur into v_sid,v_serial; --fetch the cursor -                                    --values into variables
   exit when sess_cur%notfound;
v_stat := 'alter system kill
session '||''''||v_sid||','||v_serial||''''; -- construct -                                        --the ddl statement
end loop;
close sess_cur;

here r some points for to notice:
1.if u can specifically select a singe combination of sid and serial# then u can use
a select statement with proper where clause in place of the cursor i used in the code.
but if the select statement returns more than 1 row or does not return any row then
an exception will be raised .then ur killing statement will not work.

2.there r some sessions available for which  there is no username provided in the v$session.these
sessions, u can not u can use a where caluse - where username is not null.
3.for a single username there can be more than one session available in the v$ u can use
a where cluse to select only active sessions or inactive sessions.

i tested this method ,it works nice.


Dynamic SQL or forms_ddl:
EXECUTE IMMEDIATE 'alter system kill session ''23,123''';
FORMS_DDL('alter system kill session ''23,123'';');
The parameters for kill session are 'SID,SERIAL#'.
I'm not sure if the forms_ddl command requires a ; at the end of the statement.
Of course you'd need to have privileges to kill the session.
Hope that helps!
All Courses

From novice to tech pro — start learning today.