oracle 有什么办法可以从oracle中的gv$session获取当前会话的信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28814543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any way to get information about current session from gv$session in oracle?
提问by Volodymyr Frolov
Is there any way to uniquely identify current session in GV$SESSION
view in Oracle?
有没有办法GV$SESSION
在Oracle 中唯一标识当前会话?
I've faced with the problem that the following query may return more than one row in case of Oracle RAC configuration:
我遇到的问题是,在 Oracle RAC 配置的情况下,以下查询可能返回多于一行:
SELECT SID, SERIAL#
FROM GV$SESSION
WHERE AUDSID = Sys_Context('USERENV', 'SESSIONID')
AND SID = Sys_Context('USERENV', 'SID');
Using V$MYSTAT
is not an option either, because V$MYSTAT
may not be accessible for the current session (for example when statistic is disabled).
使用V$MYSTAT
也不是一个选项,因为V$MYSTAT
当前会话可能无法访问(例如,当统计信息被禁用时)。
回答by Mark J. Bobak
Try this:
尝试这个:
SELECT SID, SERIAL#
FROM V$SESSION
WHERE AUDSID = Sys_Context('USERENV', 'SESSIONID');
Since you're interested in current session, the current session must be on the local instance (by definition), so use V$SESSION
instead of GV$SESSION
. Also, all you need is AUDSID
to uniquely identify your session.
由于您希望在本届会议上,本届会议必须在本地实例(定义),所以使用V$SESSION
的替代GV$SESSION
。此外,您所需要的只是AUDSID
唯一标识您的会话。
If you've got some reason you reallyneed to use GV$SESSION
(can't imagine why that would be), you could do this instead:
如果您有某些原因确实需要使用GV$SESSION
(无法想象为什么会这样),您可以这样做:
SELECT SID, SERIAL#
FROM GV$SESSION
WHERE AUDSID = Sys_Context('USERENV', 'SESSIONID')
AND INST_ID = USERENV('Instance');
Also, an alternate way to get the SID
of the current session is:
此外,获取SID
当前会话的另一种方法是:
select sid from v$mystat where rownum=1;
Hope that helps.
希望有帮助。
回答by aitor
Joining gv$session
and v$mystat
:)
加入gv$session
和v$mystat
:)
SELECT SID, SERIAL#,inst_id
FROM GV$SESSION
WHERE sid=(select sid from v$mystat where rownum=1);
回答by GolezTrol
Use V$SESSION
instead of GV$SESSION
使用V$SESSION
代替GV$SESSION
SELECT SID, SERIAL#
FROM V$SESSION
WHERE SID = Sys_Context('USERENV', 'SID');
回答by Vikas
Try this (will need access to v$session and v$sql views) -
试试这个(需要访问 v$session 和 v$sql 视图)-
select /*My Sess*/ 'My Sess Text = hello world @ '||systimestamp SID_SR_TXT from dual
union
select 'SID = '||sid||' Serial# = '||serial# SID_SR_TXT from v$session where sql_id in
(select sql_id from v$sql where sql_text like '% My Sess %');