Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Session information using sys_context don't show own session

314245May 28 2008 — edited May 28 2008
Hello,

I want to offer a method for users to view their sessions information
(status, logon_time, last activity...).

Users normally don't have access to v$session, v$process...
and I tried with sys_context using a procedure that system grant execute to user
and captures session_user.

After testing it (see below) I realized it did not show my own session information,
do you know why?

Suppose some misconception for my part, any explanation or different solution
for my subject would be appreciate.

create or replace
PROCEDURE SESSION_INFO AS
CURSOR c_ctx IS SELECT sys_context('USERENV', 'SESSION_USER') SESSION_USER from dual;
ctx c_ctx%ROWTYPE;
BEGIN
open c_ctx;
fetch c_ctx into ctx;
close c_ctx;
DBMS_OUTPUT.PUT_LINE('STATUS SERVER LOGON LAST_ACT MACHINE SID SERIAL#');
DBMS_OUTPUT.PUT_LINE('-------- --------- -------- -------- ------------------------- ---------- ----------');
FOR x IN
(SELECT status,
server,
logon_time,
last_call_et,
machine,
schemaname,
sid,
serial#
FROM sys.v_$session
WHERE schemaname=ctx.session_user
ORDER BY schemaname)
LOOP
DBMS_OUTPUT.PUT_LINE(rpad(x.status,8)|| ' ' || rpad(x.server, 9) || ' ' || rpad(to_char(x.logon_time, 'HH24:MI:SS'), 8) || ' ' || rpad(to_char(sysdate -x.last_call_et / 86400, 'HH24:MI:SS'), 8) || ' ' || rpad(x.machine, 25) || ' ' || ' ' || lpad(x.sid, 10) || ' ' || lpad(x.serial#, 10));
END LOOP;
END SESSION_INFO;

Two sessions for TEST, one from my sqldeveloper (id25190 machine) and another
from sqlplus in db server (delfos machine):

sqlplus TEST session:

SQL> exec system.session_info();

STATUS SERVER LOGON LAST_ACT MACHINE SID SERIAL#
-------- --------- -------- -------- ------------------------- ---------- ----------
INACTIVE DEDICATED 12:33:36 12:33:54 id25190 303 1030

PL/SQL procedure successfully completed.

Another sqlplus SYSTEM session shows two existing sessions for TEST user:

SQL> SELECT status,server,logon_time,last_call_et,machine,schemaname,sid,serial#
FROM sys.v_$session
WHERE schemaname='TEST';

STATUS SERVER LOGON_TI LAST_CALL_ET MACHINE SCHEMANAME SID SERIAL#
-------- --------- -------- ------------ --------------- ---------- ---------- ----------
INACTIVE DEDICATED 28/05/08 90 delfos TEST 298 3914
INACTIVE DEDICATED 28/05/08 891 id25190 TEST 303 1030


Thanks in advance,

Robert
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2008
Added on May 28 2008
3 comments
1,010 views