Re: How to get session number?

From: Bob Rosales <brosales_at_netcom.com>
Date: Fri, 5 Aug 1994 18:15:43 GMT
Message-ID: <brosalesCu2qq7.8Bp_at_netcom.com>


lanclosd_at_bcstec.ca.boeing.com (Dwayne K. Lanclos) writes:

>If I'm in PL/SQL, how do I obtain the current session ID? I'm not the
>DBA. I know there's a couple of tables out there (V$PROCESS, V$SESSION)
>that contain this information for the current session, however I don't
>know how to query them properly because the same user can have multiple
>concurrent sessions.
 

>I've got a batch job that needs immediate access to update a block of
>records in a table. My DBA needs my session ID so that he can determine
>the resources that I am waiting on and terminate any other sessions that
>are holding the resources I need.
 

>Thanks in advance.
>--
>Dwayne K. Lanclos lanclosd_at_lacmhs.boeing.com
 

>"War doesn't determine who's right, just who's left."

(1) make sure you have access to v$process and v$session. (2) try this sql

column "YOUR PID" format a12
select S.terminal,S.sid,

       rtrim(S.process) || ':' || rtrim(S.machine) "YOUR PID",
       P.spid "BACK PID"

from v$session S, v$process P
where S.paddr = P.addr
  and P.background is null
  and S.username = 'PUT-YOUR-NAME-HERE'

  and substr(S.program,1,7) = 'sqlplus';

I am assuming that you are running sqlplus. The SQL above displays terminal id, sid, the process id of your sqlplus process along with the name of the host where your sqlplus is originated, and the process id of your shadow process. Tailor it to fit your need. Actually, with little change of the SQL above, your DBA should be able to list who is who on the system!

Have fun.

Robert Rosales
Sonica Software Corp.
brosales_at_netcom.com Received on Fri Aug 05 1994 - 20:15:43 CEST

Original text of this message