SYS_CONTEXT 和 USERENV 查看会话ID

SELECT DISTINCT SID FROM V$MYSTAT;

SELECT USERENV('SID') FROM DUAL;

SELECT SYS_CONTEXT('USERENV', 'SID') FROM DUAL;

上面三条语句均是查看当前会话的ID,官方解释:

V$MYSTAT

This view contains statistics on the current session.

Column

Datatype

Description

SID

NUMBER

ID of the current session

STATISTIC#

NUMBER

Number of the statistic

VALUE

NUMBER

Value of the statistic

其中字段statistic#可以关联表v$statname 表的name字段看所属种类:

SELECT T.SID, T.STATISTIC#, F.NAME, T.VALUE, F.CLASS
  FROM V$MYSTAT T INNER JOIN V$STATNAME F ON T.STATISTIC# = F.STATISTIC#;

USERENV 语法

USERENV('parameter')

具体用法参考:http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions208.htm#SQLRF06157

ORACLE 用此功能只是为了保持向后兼容,建议使用功能更为强大的SYS_CONTEXT功能;具体用法参考:

http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions184.htm#i1038176

 

关于v$mystat v$sesstat v$sysstat v$statname的区别,请参考自:http://blog.csdn.net/perfect_db/article/details/16337451

 

你可能感兴趣的:(SYS_CONTEXT 和 USERENV 查看会话ID)