sys_context function

一點經驗:
  FORM6i是基於Oracle8.0開開發的,它不支持所有8i的功能。如:它不直接支持sys_context function. 而8i數據庫是支持sys_context的。變通的方法是用 sys_context在database裏create個function,再在Form trigger裏調用。
  另外,sys_context 是個非常好用的function.可用它查到用戶的信息。
  For example:
  Select sys_context('userenv','os_user') from dual;可查到用戶的OS Login.
  我覺得最重要的是
  Select sys_context('userenv','ipaddress') from dual;
  可以查出ip地址。
  補充:Predefined Attributes of Namespace USERENV
  
select SYS_CONTEXT('USERENV','CURRENT_USER') CURRENT_USER from dual;
USERENV
---built-in namespace which describes the current session.
CURRENT_USER--有很多參數,詳見下文。

這個SYS_CONTEXT是一個Function,其具體的信息可以在以下的文檔查到:
Oracle Database SQL Reference

Purpose
SYS_CONTEXT returns the value of parameter associated with the context
namespace. You can use this function in both SQL and PL/SQL statements.
主要是用來獲取用戶環境的相關參數信息,作用很大。
Oracle provides a built-in namespace called USERENV, which describes the current
session. The predefined parameters of namespace USERENV are listed followed。

常用的用如下: (更詳細的看文檔)
AUTHENTICATION_TYPE
How the user was authenticated:
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.
CURRENT_USER
The name of the user whose privilege the current session is under.
DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter.
DB_NAME
Name of the database as specified in the DB_NAME initialization parameter
HOST
Name of the host machine from which the client has connected.
INSTANCE_NAME
The instance identification name of the current instance.
IP_ADDRESS
IP address of the machine from which the client is connected.
ISDBA
TRUE if you currently have the DBA role enabled and FALSE if you do not.  
LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
The language and territory currently used by your session, along with the database character set, in this NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
OS_USER
Operating system username of the client process that initiated the database session
PROXY_USER
Name of the database user who opened the current session on behalf of SESSION_USER.
SESSION_USER
Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.
TERMINAL

The operating system identifier for the client of the current session. In distributed SQL statements, this option 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.)



SYS_CONTEXT函數非常有用,和系統觸發器結合起來可以很好的實現審計功能!
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

發佈了17 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章