SYS_CONTEXT和USERENV(OPTION)函数
2013-12-31 15:29
323 查看
SYS_CONTEXT
SyntaxDescription of the illustration sys_context.gif
Purpose
SYS_CONTEXTreturns the value of
parameterassociated with the context
namespace
at the current instant(当前实例). You can use this function in both SQL and PL/SQL statements.
SYS_CONTEXTmust be executed locally.
the context([b]context,即上下文,在数据库中是类似于表等概念,是一个数据库对象)[/b]
namespacemust
already have been created, and the associated
parameterand its value must also have beenset using the
DBMS_SESSION.
set_contextprocedure. The
namespacemust be a valid SQL identifier. The
parametername can be any string. It is
not case sensitive, but it cannot exceed 30 bytes in length.
The data type of the return value is
VARCHAR2. The default maximum size of the return value is 256 bytes(默认返回值的数据类型最大所占字节为256字节). You canoverride
this default (maximum size) by specifying the optional
lengthparameter, which must be a
NUMBERor a value that can be implicitly converted to
NUMBER(参数类型或是能隐式转换为length的数据类型必须是一个[code]NUMBER
NUMBER的类型[/code]). The valid range of values is 1 to 4000 bytes(参数length值的范围为1到4000).
If you specify an invalid value, then Oracle Database ignores it and uses the default.
Oracle provides the following built-in(即内建,也就是说已经预先在数据库中创建了的) namespaces:
USERENV- Describesthe current session(返回当前会话的信息). The predefined(预定义) parameters of
namespace
USERENVare listed in
Table 5-11.
SYS_SESSION_ROLES- Indicates whethera specified role
is currently enabled for the session. This namespace is available starting with Oracle Database 11g Release 2 (11.2.0.4).
关于context这个数据库对象,参见:
Oracle Database Security Guide for information on using the application context
feature in your application development
CREATE CONTEXT for information on creating user-defined context namespaces(如何创建用户自定义的context)
Oracle Database PL/SQL Packages and Types Reference for
information onthe
DBMS_SESSION.
set_contextprocedure(如何使用[b]the
DBMS_SESSION.
set_context来创建并设置[b]
context[/b]里的参数)[/b]
注释:
context类似于schema这个概念一样,就是一个容器,里面存放多个参数。
Examples
The following statement returns the name of the user who logged onto the database:
CONNECT OE/password SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER') FROM DUAL; SYS_CONTEXT ('USERENV', 'SESSION_USER') ------------------------------------------------------ OE
The following example queries the
SESSION_ROLESdata dictionary view to show that
RESOURCEis the only role currently enabled for the session. It then uses the
SYS_CONTEXTfunction to show that the
RESOURCErole is currently enabled for the session and the
DBArole is not.
CONNECT OE/password SELECT role FROM session_roles; ROLE -------- RESOURCE SELECT SYS_CONTEXT('SYS_SESSION_ROLES', 'RESOURCE') FROM DUAL SYS_CONTEXT('SYS_SESSION_ROLES','RESOURCE') -------------------------------------- TRUE SELECT SYS_CONTEXT('SYS_SESSION_ROLES', 'DBA') FROM DUAL; SYS_CONTEXT('SYS_SESSION_ROLES','DBA') -------------------------------------- FALSE
The following hypothetical example returns the group number that was set as the value for the attribute
group_noin the PL/SQL package that was associated with the context
hr_appswhen
hr_appswas created(假设名为
hr_apps的context已经创建好了,
group_no是它的一个参数):
SELECT SYS_CONTEXT ('hr_apps', 'group_no') "User Group" FROM DUAL; 附加: Oracle recommends that you use the [code]SYS_CONTEXTfunction with the built-in
USERENVnamespace for current functionality(即USERENV(OPTION)函数).
译文:
SYS_CONTEXT函数可以以SYS_CONTEXT ('USERENV', 'OPTION')
取代USERENV(OPTION)函数的功能。[/code]
USERENV(OPTION)函数介绍:
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;
疑问:
参数 ENTRYID 是什么意思?
相关文章推荐
- userenv和sys_context函数
- USERENV函数和SYS_CONTEXT函数使用
- sys_context函数
- oracle sys_context()函数
- oracle sys_context()函数
- SYS_CONTEXT函数,获取当前连接信息
- userenv和sys_context函数
- oracle中的userenv及sys_context的参数
- sys_context()函数功能一览
- sys_context 函数使用方法
- userenv和sys_context函数
- userenv和sys_context函数
- hylan:Oracle的USEREVN()函数 和 sys_context()函数
- sys_context函数
- oracle函数sys_context
- SYS_CONTEXT函数返回IP地址的一些误解
- USERENV和SYS_CONTEXT用法
- oracle中的userenv及sys_context的参数
- Oracle USERENV函数和sys_context函数
- oracle sys_context()函数