Two functions used to obtain session information in Oracle: oracle session
1. USERENV (OPTION)
Returns the current session information.
OPTION = 'isdba ': TRUE if the current role is a DBA; otherwise, FALSE.
OPTION = 'language' returns the character set of the database.
OPTION = 'sessionid' is the current session identifier.
OPTION = 'entryid' returns the auditable session identifier.
OPTION = 'lang 'returns the ISO Note of the session language name.
OPTION = 'instance' returns the current INSTANCE.
OPTION = 'terminal' returns the name of the current computer.
Select userenv ('language') from dual;
2. sys_context
Copy codeThe Code is as follows:
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
3. More information can be obtained by combining with the System View v $ session (applications used by the client, etc)
Copy codeThe Code is as follows:
Select *
From v $ session se,
(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) base
Where se. AUDSID = base. sessionid;