sys_context

原创
2012/06/07 16:38
阅读数 261

userenv与sys_context函数都是用来记录连接的session信息,大多用于触发器中,记录客户端的连接信息.

官方手册对userenv function有如下一段描述,对它不做过多关注。本文重点记录sys_context.

userenv

Purpose
Note:
USERENV is a legacy function that is retained for backward compatibility. Oracle recommends that you use the SYS_CONTEXT function with the built-in USERENV namespace for current functionality. See SYS_CONTEXT for more information.

sys_context

Purpose

SYS_CONTEXT returns the value of parameter associated with the context namespace at the current instant. You can use this function in both SQL and PL/SQL statements. SYS_CONTEXT must be executed locally.

The SYS_CONTEXT function is able to return the following host and IP address information for the current session:

  • TERMINAL - An operating system identifier for the current session. This is often the client machine name.
  • HOST - The host name of the client machine.
  • IP_ADDRESS - The IP address of the client machine.
  • SERVER_HOST - The host name of the server running the database instance.

The following examples show the typical output for each variant.

SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual;
SELECT SYS_CONTEXT('USERENV','HOST') FROM dual;
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;
SELECT SYS_CONTEXT('USERENV','SERVER_HOST') FROM dual;

SELECT
SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
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','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','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
from dual;

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部