这两个函数用来记录连接的session信息,经常用于触发器中,记录客户端的连接信息(比如IP)。我比较关注的是sessionid和ip,但是 select userenv('sessionid')得到的并不是用户的sid,而是v$session中的audsid,sid根据audsid再得到:
SQL> select sid from v$session where audsid=userenv('sessionid');
SID
----------
       159
至于sid和audsid的区别,自己也没太搞明白,网上摘了一段:
--from asktom
the audsid column is populated via a sequence and for normal
sessions is the same as "userenv('sessionid')" -- but for some background sessions -- it is not set
(it comes back as "0" making the view not work.
So, I'd just ignore "audsid" for now and use SID.
下面记录了两个函数的具体用法:
1、 USERENV(OPTION)
    返回当前的会话信息.
    OPTION='ISDBA'若当前是DBA角色,则为TRUE,否则FALSE.
    OPTION='LANGUAGE'返回数据库的字符集.
    OPTION='SESSIONID'为当前会话标识符.
    OPTION='ENTRYID'返回可审计的会话标识符.
    OPTION='LANG'返回会话语言名称的ISO简记.
    OPTION='INSTANCE'返回当前的实例.
   OPTION='terminal'返回当前计算机名
    SELECT USERENV('LANGUAGE') FROM DUAL;
2、返回系统会话信息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 ;
其中,第二个参数的可选值如下:

AUTHENTICATION_DATA  
Data being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
Note: You can change the return value of the AUTHENTICATION_DATA attribute using the length parameter of the syntax. Values of up to 4000 are accepted. This is the only attribute of USERENV for which Oracle implements such a change.

AUTHENTICATION_TYPE
How the user was authenticated:
DATABASE: username/password authentication
OS: operating system external user authentication
NETWORK: network protocol or ANO authentication
PROXY: OCI proxy connection authentication

BG_JOB_ID  
Job ID of the current session if it was established by an Oracle background process. Null if the session was not established by a background process.

CLIENT_INFO  
Returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.

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_SCHEMAID  
Identifier of the default schema being used in the current session.

CURRENT_USER  
The name of the user whose privilege the current session is under.

CURRENT_USERID  
User ID 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.

ENTRYID  
The available auditing entry identifier. You cannot use this option in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to true.

EXTERNAL_NAME  
External name of the database user. For SSL authenticated sessions using v.503 certificates, this field returns the distinguished name (DN) stored in the user certificate.

FG_JOB_ID  
Job ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.

HOST  
Name of the host machine from which the client has connected.

INSTANCE  
The instance identification number of the current instance.

IP_ADDRESS  
IP address of the machine from which the client is connected.

ISDBA  
TRUE if you are logged on as SYS.

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 the form:language_territory.characterset.

NETWORK_PROTOCOL  
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.

NLS_CALENDAR  
The current calendar of the current session.

NLS_CURRENCY  
The currency of the current session.

NLS_DATE_FORMAT  
The date format for the session.

NLS_DATE_LANGUAGE
The language used for expressing dates.

NLS_SORT  BINARY
or the linguistic sort basis.

NLS_TERRITORY
The territory of the current session.

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.

PROXY_USERID
Identifier 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.

SESSION_USERID  
Identifier of the database user name by which the current user is authenticated.

SESSIONID  
The auditing session identifier. You cannot use this option in distributed SQL statements.

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.)

本文出自 “帅小伙的博客” 博客,请务必保留此出处http://zhaizhenxing.blog.51cto.com/643480/134745

userenv和sys_context函数相关推荐

  1. SYS_CONTEXT函数返回IP地址的一些误解

    上次分享中曾使用了SYS_CONTEXT函数获取ip地址,但返回值为空,当时认为其是返回ipv6的地址,所以为空,但其实这是错误的结论.虽然是一个小小的知识点,但从中可以看出Oracle对于这种内置函 ...

  2. oracle sys_context()函数

    第一个参数为'USERENV',是固定的,第二个参数也是固定的,但是是多选固定,可选的值如下所示: select sys_context('USERENV','AUTHENTICATION_TYPE' ...

  3. oracle数据库userenv,oracle中的userenv及sys_context的参数

    1. USERENV(OPTION) 返回当前的会话信息. OPTION='ISDBA'若当前是DBA角色,则为TRUE,否则FALSE. OPTION='LANGUAGE'返回数据库的字符集. OP ...

  4. oracle数据库userenv,Oracle数据库中userenv、sys_context的参数

    1. USERENV(OPTION) 返回当前的会话信息. OPTION= 1. USERENV(OPTION) 返回当前的会话信息. OPTION='ISDBA'若当前是DBA角色,则为TRUE,否 ...

  5. oracle中treat函数,Oracle 函数概览

    -- Start Oracle 内置的函数真的是很多,要精通每个函数几乎是不可能的,所以本文并不打算介绍每个函数的具体用法,而是提供一个概览,让您了解每个函数的功能,这样,当你感觉你需要某些功能的函数 ...

  6. oracle 函数使用

    常用函数:substr和instr 1.SUBSTR(string,start_position,[length])    求子字符串,返回字符串 解释:string 元字符串       start ...

  7. oracle的跨会话变量,oracle 回话环境变量 userenv ,oracle connetion context 会话环境 连接的会话环境...

    评论 # re: oracle 回话环境变量 userenv 2008-08-03 11:13 小高 关于sys_context()函数功能一览 包括取本地ip,服务器端domian/db_name- ...

  8. oracle--09常用函数

    Oracle内置函数日期函数字符串函数统计函数 to_char();--转换为字符串 to_number();--转换为数值类型 to_date();--转换为日期类型   1.常用数学运算函数 ab ...

  9. oracle如何进入管理器,oracle 启动管理器

    oracle 启动管理器 emctl start dbconsole 是10g的启动console服务的命令 将OEM服务停止emctl stop dbconsole emctl start dbco ...

最新文章

  1. 基于区域的CNN(R-CNN)
  2. 总结一下MySQL中的锁机制
  3. 基于nanopi的即时通讯系统
  4. 第十六课、Qt对象间的父子关系------------------狄泰软件学院
  5. serial driver 1
  6. redhat和ubuntu上部署本地源
  7. 2019 WAIC | 腾讯张正友:人工智能的热与酷
  8. delimited mysql_在MySQL中存儲逗號分隔的數據
  9. FatMouse's Speed hdu 1160(动态规划,最长上升子序列+记录路径)
  10. FPGA 常用AXI总线介绍
  11. wps复选框怎么设置_wps中excel复选框怎么设置
  12. 关于聚光灯各种衰减系数的尝试体会聚光灯的效果
  13. Python数据处理之数据聚合
  14. java实现1 12 123 1234 12345 123456 输出
  15. 通俗解释:什么是临床预测模型
  16. 算法练习-鸡兔同笼问题
  17. FFmpeg滤镜:制作图片视频流(续)
  18. 文献阅读07期:智网中动态电价对太阳能板普及的影响
  19. 以后面试再也不怕被问Java并发编程了,多亏了这本PDF电子书
  20. 计算机网络网桥思维导图,《王道计算机网络》学习笔记总目录+思维导图

热门文章

  1. 2019下半年的教师资格考试~学霸大佬们总结的记忆口诀涨分必备
  2. 腾讯云安装mysql_详解腾讯云CentOS7.0使用yum安装mysql及使用遇到的问题
  3. 原生 html 绘制表格
  4. 美国近年来推进“新基建”的布局及启示
  5. css3 图片圆形显示 如何CSS将正方形图片显示为圆形图片布局
  6. 动态规划——宠物小精灵之收服
  7. mybatis+spring+springmvc ssm整合
  8. Matlab课后笔记之霍夫变换(Hough Transform)
  9. opencv26:霍夫直线变换
  10. 移动式无线蓝牙RFID+二维码扫描一体机|读卡器HX-R58C-B在安卓与苹果手机上如何操作?