miércoles, 29 de abril de 2009

sys_context - Obtener información de la sesión

sys_context( namespace, parameter, [ length ] )

Surgió la necesidad de obtener el usuario del S.O. con el que estaba
logeado el usuario que había iniciado la sesión de Oracle, y lo obtuvimos así:

Para obtener el usuario del S.O:

SELECT sys_context('USERENV', 'OS_USER') FROM dual

Otros ejemplos:

Para obtener el nombre de la base de datos:
SELECT sys_context('USERENV', 'DB_NAME') FROM dual

Para obtener el eschema actual de la base de datos:
SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual



Existen muchos otros parámetros.

Dejo este enlace
http://www.techonthenet.com/oracle/functions/sys_context.php

Los parametros posibles para el namespace 'USERENV' son estos:

  • AUDITED_CURSORID: Returns the cursor ID of the SQL that triggered the audit
  • AUTHENTICATION_DATA: Authentication data
  • AUTHENTICATION_TYPE: Describes how the user was authenticated. Can be one of the following values: Database, OS, Network, or Proxy
  • BG_JOB_ID: If the session was established by an Oracle background process, this parameter will return the Job ID. Otherwise, it will return NULL.
  • CLIENT_IDENTIFIER: Returns the client identifier (global context)
  • CLIENT_INFO: User session information
  • CURRENT_SCHEMA: Returns the default schema used in the current schema
  • CURRENT_SCHEMAID: Returns the identifier of the default schema used in the current schema
  • CURRENT_SQL: Returns the SQL that triggered the audit event
  • CURRENT_USER: Name of the current user
  • CURRENT_USERID: Userid of the current user
  • DB_DOMAIN: Domain of the database from the DB_DOMAIN initialization parameter
  • DB_NAME: Name of the database from the DB_NAME initialization parameter
  • ENTRYID: Available auditing entry identifier
  • EXTERNAL_NAME: External of the database user
  • FG_JOB_ID: If the session was established by a client foreground process, this parameter will return the Job ID. Otherwise, it will return NULL.
  • GLOBAL_CONTEXT_MEMORY: The number used in the System Global Area by the globally accessed context
  • HOST:nName of the host machine from which the client has connected
  • INSTANCE: The identifier number of the current instance
  • IP_ADDRESS: IP address of the machine from which the client has connected
  • ISDBA: Returns TRUE if the user has DBA privileges. Otherwise, it will return FALSE.
  • LANG: The ISO abbreviate for the language
  • LANGUAGE: The language, territory, and character of the session. In the following format: language_territory.characterset
  • NETWORK_PROTOCOL: Network protocol used
  • NLS_CALENDAR: The calendar of the current session
  • NLS_CURRENCY: The currency of the current session
  • NLS_DATE_FORMAT: The date format for the current session
  • NLS_DATE_LANGUAGE: The language used for dates
  • NLS_SORT: BINARY or the linguistic sort basis
  • NLS_TERRITORY: The territory of the current session
  • OS_USER: The OS username for the user logged in
  • PROXY_USER: The name of the user who opened the current session on behalf of SESSION_USER
  • PROXY_USERID: The identifier of the user who opened the current session on behalf of SESSION_USER
  • SESSION_USER: The database user name of the user logged in
  • SESSION_USERID: The database identifier of the user logged in
  • SESSIONID: The identifier of the auditing session
  • TERMINAL: The OS identifier of the current session

No hay comentarios:

Publicar un comentario