- 浏览: 5174922 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
silence19841230:
先拿走看看
SpringBoot2.0开发WebSocket应用完整示例 -
wallimn:
masuweng 写道发下源码下载地址吧!三个相关文件打了个包 ...
SpringBoot2.0开发WebSocket应用完整示例 -
masuweng:
发下源码下载地址吧!
SpringBoot2.0开发WebSocket应用完整示例 -
masuweng:
SpringBoot2.0开发WebSocket应用完整示例 -
wallimn:
水淼火 写道你好,我使用以后,图标不显示,应该怎么引用呢,谢谢 ...
前端框架iviewui使用示例之菜单+多Tab页布局
这两个函数用来记录连接的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
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
发表评论
-
Oracle连接故障的排除
2024-09-09 22:33 674Oracle版本为11G,操作系统为Windows Ser ... -
Oracle数据库相关系统突然提示“SQLException:违反协议”
2024-02-19 15:50 5190SQLException:违反协议这个异常可能由很多的 ... -
CentOS在Docker中安装Oracle
2024-02-06 12:13 12801.拉取Oracle镜像,并检 ... -
Windows Server安装oracle数据库一直停在82%
2023-02-04 12:01 627网上有个说法:服务器超过一定数量的CPU后,将不能正常安装 ... -
ORA-04030错误处理
2023-02-04 11:52 2709【错误描述】 错误信息如下: ORA-04030:在尝 ... -
ORA-04030错误处理
2023-02-04 11:45 403【错误描述】 错误信息如下: ORA-04030:在尝 ... -
Linux安装MySQL数据库
2019-06-10 22:27 18301.进入安装包所在目录,解压: tar zxvf mysql- ... -
确定MySQL在Linux系统中配置文件的位置
2019-04-14 19:30 27881.通过which mysql命令来查看mysql的安装位置。 ... -
mysql set names 命令和 mysql 字符编码问题
2019-04-12 00:34 1167转自:https://www.cnblogs.com/digd ... -
MYSQL中取当前周/月/季/年的第一天与最后一天
2018-11-17 23:16 2224转自:https://blog.csdn.net/ ... -
Oracle删除大量数据的实践
2016-11-07 18:03 5847一、引言 从来没有 ... -
Oracle 数据库简明教程 V0.1
2016-03-23 21:01 2073供初学者入门学习使用,以开发者常见、常用的知识为主,基本上 ... -
Oracle拆分字符串函数
2016-03-23 10:58 3375create or replace type string ... -
Oracle数据库远程连接无响应
2016-03-21 10:20 4333故障现象: 服务器本机使用sqlplus / as s ... -
Oracle PGA详解
2015-10-21 15:34 11498转自:http://yanguz123.iteye.com/b ... -
Oracle12C导入dmp数据
2015-10-08 23:43 20560Oracle12C,发生了较大的变化。以前熟悉的东西变得陌 ... -
SQLLDR数据导入小结
2015-07-25 22:06 75531.创建数据表 CREATE TABLE ... -
Window7安装Oracle10
2015-03-06 12:14 1630每次安装都要百度,转到自己的博客上,找起来方便,还能增加访 ... -
Oracle SQL Developer 连接 Mysql 数据库
2015-02-25 19:36 3693下载JDBC包,解压缩这里只要mysql-connector- ... -
Mysql数据备份与恢复
2015-02-25 19:15 1373备份/恢复策略 1. 要定期做 mysql备份,并考虑系统可以 ...
相关推荐
Oracle 中的 sys_context 函数 sys_context 函数是 Oracle 提供的一个获取环境上下文信息的...sys_context 函数是一个非常有用的函数,它可以帮助开发者获取当前环境的各种信息,从而实现更加灵活和智能的应用程序。
USERENV函数和SYS_CONTEXT函数都是Oracle数据库中非常重要的函数,它们可以用于获取当前会话的信息,例如当前用户、当前实例、当前语言等。这两个函数的使用可以帮助开发者更好地了解当前会话的信息,从而更好地开发...
### Oracle9.2_SYS_CONTEXT函数详解 在Oracle数据库系统中,`SYS_CONTEXT`函数是一个非常实用的功能,它允许用户从不同的上下文中检索信息。在Oracle9.2版本中,这个函数提供了一种灵活的方式来访问与当前会话或...
#### 二、SYS_CONTEXT函数详解 `SYS_CONTEXT`函数用于获取当前会话或系统环境的信息。具体来说,它可以返回与用户、会话和系统设置相关的多种信息。以下是`SYS_CONTEXT`的一些常用选项及其含义: - **`'USERENV','...
`SYS_CONTEXT`函数用于获取当前会话的上下文信息,如终端、语言环境等。 **示例:** ```sql SELECT SYS_CONTEXT('USERENV', 'TERMINAL') terminal, SYS_CONTEXT('USERENV', 'LANGUAGE') language, SYS_CONTEXT('...
- **解答**: `SYS_CONTEXT`函数可以用来获取与当前会话相关的各种环境信息。例如: ```sql SELECT SYS_CONTEXT('USERENV', 'TERMINAL') terminal, SYS_CONTEXT('USERENV', 'LANGUAGE') language, SYS_CONTEXT('...
这些数据通常以键值对的形式存在,可以通过SYS_CONTEXT函数进行访问。相比于旧版的USERENV函数,SYS_CONTEXT提供了更广泛的功能,不仅可以获取系统环境信息,还能处理自定义的应用程序数据。 在Oracle 9i中,After ...
`SYS_CONTEXT`函数用于获取Oracle环境中的上下文信息,例如会话参数、实例配置等。其具体用法如下: ```sql SELECT SYS_CONTEXT('USERENV', 'TERMINAL') terminal, SYS_CONTEXT('USERENV', 'LANGUAGE') language, ...
综上所述,掌握Oracle的SYS_CONTEXT函数能够帮助管理员和开发者更好地理解和控制数据库会话,提高系统的安全性,并在遇到SQL注入等问题时进行有效防护。通过灵活运用此函数,可以实现对用户会话的精细化管理和监控,...
本文将详细解析两个常用的函数:USERENV和sys_context,以及它们如何帮助我们获取关于当前会话的各种信息。 首先,`USERENV`函数是一个内置的PL/SQL函数,用于获取与当前会话相关的各种环境变量。例如: 1. `...
7. **SYS_CONTEXT用法**:`SYS_CONTEXT`函数用于获取当前会话的上下文信息,如用户、环境变量等。例如,`SELECT SYS_CONTEXT('USERENV', 'SESSION_USER') FROM dual;` 8. **日期函数**:Oracle提供了丰富的日期函数...
接下来的`SELECT`语句从`SYS_CONTEXT`函数获取当前会话的用户和IP地址。`IF`结构检查用户是否为`EPAY_USER`,如果是,则进一步检查IP地址是否在允许的列表内。如果不在,触发器通过`RAISE_APPLICATION_ERROR`函数抛...
3. SYS_CONTEXT():获取数据库会话的上下文信息,如SYS_CONTEXT('USERENV', 'SESSION_USER')返回当前会话的用户。 了解并熟练掌握这些Oracle SQL内置函数,不仅可以提高查询效率,还能在处理复杂的数据问题时...
SELECT SYS_CONTEXT('USERENV', 'TERMINAL') FROM dual; -- 获取主机名 SELECT SYS_CONTEXT('USERENV', 'LANGUAGE') FROM dual; -- 获取当前语言环境 ``` 3. 获取随机数 Dual 表可以用来生成随机数,例如: ```...
3. **获取系统信息**:例如主机名、语言环境等:`SELECT SYS_CONTEXT('USERENV', 'TERMINAL') FROM DUAL;`,`SELECT SYS_CONTEXT('USERENV', 'language') FROM DUAL;` 4. **生成随机数**:`SELECT DBMS_RANDOM....
5. **Oracle 特殊函数**:`sys_Context & USERENV.txt`可能涉及Oracle的两个特殊函数,SYS_CONTEXT用于获取会话级别的信息,USERENV则提供当前用户环境的详细信息,如会话的主机名、当前用户、默认表空间等。...
此处的关键函数`sys_context('userenv','ip_address')`用于获取客户端的IP地址。需要注意的是,该函数可能无法在所有环境中都能成功获取客户端IP地址,具体情况取决于Oracle服务器的配置和客户端环境。 #### 四、...
- **sys_context**: 返回特定命名空间中上下文的值。 - **dbms_random**: 包含用于生成随机数的函数。 - **utl_inaddr.get_host_address**: 获取主机地址。 以上内容涵盖了Oracle中常见的函数及其用途,学习和掌握...