ASK_tom 文章3 檢視當前使用者的SID等v$session資訊 zt
方法有三個
1。select * from v$session where audsid=userenv('sessionid');
2。SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER') FROM DUAL;
3。select * from v$session where sid = ( select sid from v$mystat where rownum=1);
[@more@]第一 和第三個都是使用過, 第2個我還真的第一次見過!記住了!!!!
方法(一) 使用 userenv 函式
select sid,audsid from v$session where audsid=userenv('sessionid');
select sid,audsid from v$session where audsid=userenv('sessionid');
引數可以是如下!
CLIENT_INFO
CLIENT_INFO returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
CLIENT_INFO
CLIENT_INFO returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
Caution: Some commercial applications may be using this context value. Check the applicable documentation for those applications to determine what restrictions they may impose on use of this context area.
See Also:
Oracle9i Database Concepts for more on application context
CREATE CONTEXT and SYS_CONTEXT
ENTRYID
ENTRYID returns available auditing entry identifier. You cannot use this attribute in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to TRUE.
ISDBA
ISDBA returns 'TRUE' if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
LANG
LANG returns the ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
LANGUAGE returns the language and territory currently used by your session along with the database character set in this form:
CREATE CONTEXT and SYS_CONTEXT
ENTRYID
ENTRYID returns available auditing entry identifier. You cannot use this attribute in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to TRUE.
ISDBA
ISDBA returns 'TRUE' if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
LANG
LANG returns the ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
LANGUAGE returns the language and territory currently used by your session along with the database character set in this form:
language_territory.characterset
SESSIONID
SESSIONID returns your auditing session identifier. You cannot use this attribute in distributed SQL statements.
TERMINAL
TERMINAL returns the operating system identifier for your current session's terminal. In distributed SQL statements, this attribute returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations.
Examples
The following example returns the LANGUAGE parameter of the current session:
The following example returns the LANGUAGE parameter of the current session:
SELECT USERENV('LANGUAGE') "Language" FROM DUAL;
Language
-----------------------------------
AMERICAN_AMERICA.WE8DEC
-----------------------------------
AMERICAN_AMERICA.WE8DEC
方法(二) 使用SYS_CONTEXT 函式
SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER') FROM DUAL;第一個引數是'USERENV' 第二個引數
SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER') FROM DUAL;第一個引數是'USERENV' 第二個引數
Parameter Return Value Return Length (bytes)
AUDITED_CURSORID
Returns the cursor ID of the SQL that triggered the audit.
NA
AUTHENTICATION_DATA
Data being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
AUDITED_CURSORID
Returns the cursor ID of the SQL that triggered the audit.
NA
AUTHENTICATION_DATA
Data being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
Note: You can change the return value of the AUTHENTICATION_DATA attribute using the length parameter of the syntax. Values of up to 4000 are accepted. This is the only attribute of USERENV for which Oracle implements such a change.
256
AUTHENTICATION_TYPE
How the user was authenticated:
256
AUTHENTICATION_TYPE
How the user was authenticated:
DATABASE: user name/password authentication
OS: operating system external user authentication
NETWORK: network protocol or ANO authentication
PROXY: OCI proxy connection authentication
30
BG_JOB_ID
Job ID of the current session if it was established by an Oracle background process. Null if the session was not established by a background process.
64
CLIENT_IDENTIFIER
Returns the client session identifier in the global context--that is, the globally accessed application context or (in the OCI context) the OCI_ATTR_CLIENT_IDENTIFIER attribute. If no globally relevant identifier has been set, returns null.
NA
CLIENT_INFO
Returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
64
CURRENT_SCHEMA
Name of the default schema being used in the current schema. This value can be changed during the session with an ALTER SESSION SET CURRENT_SCHEMA statement.
30
CURRENT_SCHEMAID
Identifier of the default schema being used in the current session.
30
CURRENT_SQL
Returns the current SQL that triggered the fine-grained auditing event. You can specify this attribute only inside the event handler for the Fine-Grained Auditing feature.
64
CURRENT_USER
The name of the user whose privilege the current session is under.
30
CURRENT_USERID
User ID of the user whose privilege the current session is under.
30
DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter.
256
DB_NAME
Name of the database as specified in the DB_NAME initialization parameter.
30
ENTRY_ID
The available auditing entry identifier. You cannot use this attribute in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to TRUE.
30
EXTERNAL_NAME
External name of the database user. For SSL authenticated sessions using v.503 certificates, this field returns the distinguished name (DN) stored in the user certificate.
256
FG_JOB_ID
Job ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.
30
GLOBAL_CONTEXT_MEMORY
Returns the number being used in the System Global Area by the globally accessed context.
NA
HOST
Name of the host machine from which the client has connected.
54
INSTANCE
The instance identification number of the current instance.
30
IP_ADDRESS
IP address of the machine from which the client is connected.
30
ISDBA
Returns TRUE if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
30
LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
62
LANGUAGE
The language and territory currently used by your session, along with the database character set, in this form:
OS: operating system external user authentication
NETWORK: network protocol or ANO authentication
PROXY: OCI proxy connection authentication
30
BG_JOB_ID
Job ID of the current session if it was established by an Oracle background process. Null if the session was not established by a background process.
64
CLIENT_IDENTIFIER
Returns the client session identifier in the global context--that is, the globally accessed application context or (in the OCI context) the OCI_ATTR_CLIENT_IDENTIFIER attribute. If no globally relevant identifier has been set, returns null.
NA
CLIENT_INFO
Returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
64
CURRENT_SCHEMA
Name of the default schema being used in the current schema. This value can be changed during the session with an ALTER SESSION SET CURRENT_SCHEMA statement.
30
CURRENT_SCHEMAID
Identifier of the default schema being used in the current session.
30
CURRENT_SQL
Returns the current SQL that triggered the fine-grained auditing event. You can specify this attribute only inside the event handler for the Fine-Grained Auditing feature.
64
CURRENT_USER
The name of the user whose privilege the current session is under.
30
CURRENT_USERID
User ID of the user whose privilege the current session is under.
30
DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter.
256
DB_NAME
Name of the database as specified in the DB_NAME initialization parameter.
30
ENTRY_ID
The available auditing entry identifier. You cannot use this attribute in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to TRUE.
30
EXTERNAL_NAME
External name of the database user. For SSL authenticated sessions using v.503 certificates, this field returns the distinguished name (DN) stored in the user certificate.
256
FG_JOB_ID
Job ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.
30
GLOBAL_CONTEXT_MEMORY
Returns the number being used in the System Global Area by the globally accessed context.
NA
HOST
Name of the host machine from which the client has connected.
54
INSTANCE
The instance identification number of the current instance.
30
IP_ADDRESS
IP address of the machine from which the client is connected.
30
ISDBA
Returns TRUE if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
30
LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
62
LANGUAGE
The language and territory currently used by your session, along with the database character set, in this form:
language_territory.characterset
52
NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
256
NLS_CALENDAR
The current calendar of the current session.
62
NLS_CURRENCY
The currency of the current session.
62
NLS_DATE_FORMAT
The date format for the session.
62
NLS_DATE_LANGUAGE
The language used for expressing dates.
62
NLS_SORT
BINARY or the linguistic sort basis.
62
NLS_TERRITORY
The territory of the current session.
62
OS_USER
Operating system user name of the client process that initiated the database session.
30
PROXY_USER
Name of the database user who opened the current session on behalf of SESSION_USER.
30
PROXY_USERID
Identifier of the database user who opened the current session on behalf of SESSION_USER.
30
SESSION_USER
Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.
30
SESSION_USERID
Identifier of the database user name by which the current user is authenticated.
30
SESSIONID
The auditing session identifier. You cannot use this attribute in distributed SQL statements.
30
TERMINAL
The operating system identifier for the client of the current session. In distributed SQL statements, this attribute returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations. (The return length of this parameter may vary by operating system.)
10
52
NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
256
NLS_CALENDAR
The current calendar of the current session.
62
NLS_CURRENCY
The currency of the current session.
62
NLS_DATE_FORMAT
The date format for the session.
62
NLS_DATE_LANGUAGE
The language used for expressing dates.
62
NLS_SORT
BINARY or the linguistic sort basis.
62
NLS_TERRITORY
The territory of the current session.
62
OS_USER
Operating system user name of the client process that initiated the database session.
30
PROXY_USER
Name of the database user who opened the current session on behalf of SESSION_USER.
30
PROXY_USERID
Identifier of the database user who opened the current session on behalf of SESSION_USER.
30
SESSION_USER
Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.
30
SESSION_USERID
Identifier of the database user name by which the current user is authenticated.
30
SESSIONID
The auditing session identifier. You cannot use this attribute in distributed SQL statements.
30
TERMINAL
The operating system identifier for the client of the current session. In distributed SQL statements, this attribute returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations. (The return length of this parameter may vary by operating system.)
10
select
SYS_CONTEXT('USERENV','TERMINAL') terminal,
SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
SYS_CONTEXT('USERENV','ENTRYID') entryid,
SYS_CONTEXT('USERENV','ISDBA') isdba,
SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,
SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,
SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,
SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE') nls_date_language,
SYS_CONTEXT('USERENV','NLS_SORT') nls_sort,
SYS_CONTEXT('USERENV','CURRENT_USER') current_user,
SYS_CONTEXT('USERENV','CURRENT_USERID') current_userid,
SYS_CONTEXT('USERENV','SESSION_USER') session_user,
SYS_CONTEXT('USERENV','SESSION_USERID') session_userid,
SYS_CONTEXT('USERENV','PROXY_USER') proxy_user,
SYS_CONTEXT('USERENV','PROXY_USERID') proxy_userid,
SYS_CONTEXT('USERENV','DB_DOMAIN') db_domain,
SYS_CONTEXT('USERENV','DB_NAME') db_name,
SYS_CONTEXT('USERENV','HOST') host,
SYS_CONTEXT('USERENV','OS_USER') os_user,
SYS_CONTEXT('USERENV','EXTERNAL_NAME') external_name,
SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address,
SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') network_protocol,
SYS_CONTEXT('USERENV','BG_JOB_ID') bg_job_id,
SYS_CONTEXT('USERENV','FG_JOB_ID') fg_job_id,
SYS_CONTEXT('USERENV','AUTHENTICATION_TYPE') authentication_type,
SYS_CONTEXT('USERENV','AUTHENTICATION_DATA') authentication_data
from dual;
SYS_CONTEXT('USERENV','TERMINAL') terminal,
SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
SYS_CONTEXT('USERENV','ENTRYID') entryid,
SYS_CONTEXT('USERENV','ISDBA') isdba,
SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,
SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,
SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,
SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE') nls_date_language,
SYS_CONTEXT('USERENV','NLS_SORT') nls_sort,
SYS_CONTEXT('USERENV','CURRENT_USER') current_user,
SYS_CONTEXT('USERENV','CURRENT_USERID') current_userid,
SYS_CONTEXT('USERENV','SESSION_USER') session_user,
SYS_CONTEXT('USERENV','SESSION_USERID') session_userid,
SYS_CONTEXT('USERENV','PROXY_USER') proxy_user,
SYS_CONTEXT('USERENV','PROXY_USERID') proxy_userid,
SYS_CONTEXT('USERENV','DB_DOMAIN') db_domain,
SYS_CONTEXT('USERENV','DB_NAME') db_name,
SYS_CONTEXT('USERENV','HOST') host,
SYS_CONTEXT('USERENV','OS_USER') os_user,
SYS_CONTEXT('USERENV','EXTERNAL_NAME') external_name,
SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address,
SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') network_protocol,
SYS_CONTEXT('USERENV','BG_JOB_ID') bg_job_id,
SYS_CONTEXT('USERENV','FG_JOB_ID') fg_job_id,
SYS_CONTEXT('USERENV','AUTHENTICATION_TYPE') authentication_type,
SYS_CONTEXT('USERENV','AUTHENTICATION_DATA') authentication_data
from dual;
方法三
select * from v$session where sid = ( select sid from v$mystat where rownum=1);
檢視基礎表
select * from V$fixed_View_Definition
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82387/viewspace-1026309/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檢視當前使用者執行語句等資訊
- 檢視oracle當前sessionOracleSession
- 【轉】檢視Oracle當前使用者下的資訊Oracle
- v$session檢視中的sid和serial#研究Session
- 檢視當前會話session id方法:會話Session
- 【轉載】檢視當前會話SID的三種方法會話
- V$ACTIVE_SESSION_HISTORY 檢視中包含的資訊Session
- v$session 檢視Session
- Linux 下檢視系統當前登入使用者資訊Linux
- oracle獲取當前會話(程式)session id(sid)Oracle會話Session
- oracle檢視允許的最大連線數和當前連線數等資訊Oracle
- Oracle 檢視當前會話 SESSION ID 方法 說明Oracle會話Session
- Oracle動態效能檢視之v$session_longops ztOracleSessionGo
- 檢視當前使用者正在等待事件事件
- V$SESSION的SID&SERIAL#Session
- Linux檢視環境變數當前資訊和檢視命令Linux變數
- v$session/v$process檢視涉及的相關會話資訊的查詢Session會話
- Linux下用於檢視系統當前登入使用者資訊Linux
- 【會話】V$SESSION檢視會話Session
- 檢視當前登入的使用者及其IP地址
- 使用者查詢當前session IDSession
- V$session 檢視的小運用Session
- v$session - 你看到的event真的是session當前的等待事件麼?Session事件
- 在Linux中,如何檢視當前系統的版本資訊?Linux
- v$session_wait和v$session_event檢視SessionAI
- 檢視資料庫的當前連線session,以及其執行的sql資料庫SessionSQL
- 檢視linux系統當前登陸的使用者Linux
- 幾個檢視 v$mystat v$systata v$sessionSession
- v$active_session_history檢視Session
- Linux檢視和剔除當前登入使用者Linux
- V$ACTIVE_SESSION_HISTORY檢視的使用Session
- V$SESSION_LONGOPS 檢視的用法SessionGo
- 檢視git當前版本號Git
- 檢視當前系統程式
- 檢視鎖定的session資訊指令碼Session指令碼
- 使用者/伺服器程式概念及v$session/V$PROCESS檢視簡介伺服器Session
- v$active_session_history檢視[轉]Session
- 效能檢視 V$Session_LONGOPSSessionGo