如何取得Oracle當前會話的ID(Session ID)

來源:互聯網
上載者:User

取得Oracle當前會話的ID(Session ID)有3種方法:

1. 下面這個應當是大家常用的.

SQL> SELECT SID FROM V$MYSTAT WHERE ROWNUM =1;

       SID

----------

       140

2. 下面一個更簡單, 但只能在Oracle 10g及以上版本中使用.

SQL> SELECT USERENV('SID') FROM DUAL;

USERENV('SID')

--------------

           140

3. 下面這個方法我有時也用, 因為不想用最上面的SQL去寫一個子查詢, 發現在Oracle 9i上很正常, 但在Oracle 10g上常常返回兩行, 因此不能再使用它了.

SQL> SELECT SID FROM V$SESSION WHERE AUDSID=USERENV('SESSIONID');

       SID

----------

       140

       142

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.