Oracle/PLSQL: Sys_Context Function(轉自http://www.techonthenet.com)

hzh_hu發表於2009-06-19


In Oracle/PLSQL, the sys_context function can be used to retrieve information about the Oracle environment.

The syntax for the sys_context function is:

sys_context( namespace, parameter, [ length ] )

namespace is an Oracle namespace that has already been created. If the namespace of 'USERENV' is used, attributes describing the current Oracle session can be returned.

parameter is a valid attribute that has been set using the DBMS_SESSION.set_context procedure.

length is optional. It is the length of the return value in bytes. If this parameter is omitted or if an invalid entry is provided, the sys_context function will default to 256 bytes.


The valid parameters for the namespace called 'USERENV' are as follows:

Parameter Explanation Return Length
AUDITED_CURSORIDReturns the cursor ID of the SQL that triggered the auditN/A
AUTHENTICATION_DATAAuthentication data256
AUTHENTICATION_TYPEDescribes how the user was authenticated. Can be one of the following values: Database, OS, Network, or Proxy30
BG_JOB_IDIf the session was established by an Oracle background process, this parameter will return the Job ID. Otherwise, it will return NULL.30
CLIENT_IDENTIFIERReturns the client identifier (global context)64
CLIENT_INFOUser session information64
CURRENT_SCHEMAReturns the default schema used in the current schema30
CURRENT_SCHEMAIDReturns the identifier of the default schema used in the current schema30
CURRENT_SQLReturns the SQL that triggered the audit event64
CURRENT_USERName of the current user30
CURRENT_USERIDUserid of the current user30
DB_DOMAINDomain of the database from the DB_DOMAIN initialization parameter256
DB_NAMEName of the database from the DB_NAME initialization parameter30
ENTRYIDAvailable auditing entry identifier30
EXTERNAL_NAMEExternal of the database user256
FG_JOB_IDIf the session was established by a client foreground process, this parameter will return the Job ID. Otherwise, it will return NULL.30
GLOBAL_CONTEXT_MEMORYThe number used in the System Global Area by the globally accessed contextN/A
HOSTName of the host machine from which the client has connected54
INSTANCEThe identifier number of the current instance30
IP_ADDRESSIP address of the machine from which the client has connected30
ISDBAReturns TRUE if the user has DBA privileges. Otherwise, it will return FALSE.30
LANGThe ISO abbreviate for the language62
LANGUAGEThe language, territory, and character of the session. In the following format:
language_territory.characterset
52
NETWORK_PROTOCOLNetwork protocol used256
NLS_CALENDARThe calendar of the current session62
NLS_CURRENCYThe currency of the current session62
NLS_DATE_FORMATThe date format for the current session62
NLS_DATE_LANGUAGEThe language used for dates62
NLS_SORTBINARY or the linguistic sort basis62
NLS_TERRITORYThe territory of the current session62
OS_USERThe OS username for the user logged in30
PROXY_USERThe name of the user who opened the current session on behalf of SESSION_USER30
PROXY_USERIDThe identifier of the user who opened the current session on behalf of SESSION_USER30
SESSION_USERThe database user name of the user logged in30
SESSION_USERIDThe database identifier of the user logged in30
SESSIONIDThe identifier of the auditing session30
TERMINALThe OS identifier of the current session10
[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/95530/viewspace-1023318/,如需轉載,請註明出處,否則將追究法律責任。

相關文章