技术2022-05-11  23

    一点经验:   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 》PurposeSYS_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_NAMEThe 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函数非常有用,和系统触发器结合起来可以很好的实现审计功能!selectSYS_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_datafrom dual