beware!. test the script first.
-- i have commented the execute statement ( dynamic
--sql) which will actually do the job. ( i cant kill my
-- users~!!!
SQL> ed
Wrote file afiedt.buf
1 select username,status,logon_time from v$session
2 where status='INACTIVE' AND
3* TO_CHAR(SYSDATE,'HH') - TO_CHAR(LOGON_TIME,'HH') >=2
SQL> /
USERNAME STATUS LOGON_TIME
------------------------------ -------- --------------------
LAWSON INACTIVE 08-jan-2003 08:42:14
LAWSON INACTIVE 08-jan-2003 08:54:45
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure kill_session
2 as
3 cursor c1 is select * from v$session
4 where status='INACTIVE' AND
5 TO_CHAR(SYSDATE,'HH') - TO_CHAR(LOGON_TIME,'HH') >=2;
6 begin
7 for mag in c1 loop
8 exit when c1%notfound;
9 dbms_output.put_line('user to be killed: '||mag.username);
10 -- execute immediate ('alter system kill session ('||mag.sid||','||mag.serial#||')');
11 end loop;
12* end;
SQL> /
Procedure created.
SQL> exec kill_session;
user to be killed: LAWSON
user to be killed: LAWSON
PL/SQL procedure successfully completed.
----------------------------------------------------------------------
i would prefer to do the same ,
by seeting up the profile, utilizing
IDLE_TIME & CONNECT_TIME