问题描述
在Oracle数据库中,以下各项之间有何区别:
In an Oracle Database, what are the differences between the following:
- user()
- sys_context('USERENV','CURRENT_USER')
- sys_context('USERENV','SESSION_USER')
这些与当前用户"无关的值是否也是可能的?
Are these also possible related values to whatever 'the current user' is?
- sys_context('USERENV','CURRENT_SCHEMA')
- sys_context('USERENV','AUTHENTICATED_IDENTITY')
我特别感兴趣的是哪些可以更改,哪些可以更改,哪些不能更改值,哪些基于连接类型具有不同的值以及哪些始终是用于架构的模式登录数据库.
I am specifically interested in which ones can change, what can change them, which ones can not change value, which ones have different values based on connection type, and which one(s) is(are) always the schema used to log into the database.
在我的大多数测试中,值始终相同.唯一的例外是运行以下命令来更改"CURRENT_SCHEMA"时:
In most of my testing the values are always the same. The only exception would be when running the following to alter 'CURRENT_SCHEMA':
alter session set current_schema=<SCHEMA>
执行以下操作会导致错误:
Doing following results in an error:
alter session set current_user=<USER> --even as sys/system, which is good I suppose
因此,所有这些都具有某种安全性/规则.但是,在拥有SESSION_USER和CURRENT_USER之后必须有一些原因.我还认为user()可能是sys_context('USERENV','CURRENT_USER')的快捷方式,但我找不到与此有关的文档.
So there is some kind of security/rules around all of this. However there must be some reason behind having a SESSION_USER and a CURRENT_USER. I also suppose user() could be a shortcut to sys_context('USERENV', 'CURRENT_USER'), but I could find no documentation on the matter.
推荐答案
来自手册,网址为: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions184.htm#SQLRF51825
SESSION_USER
因此,特别是在存储过程或函数中使用CURRENT_USER时,SESSION_USER和CURRENT_USER之间有一个差异.
So there is a difference between SESSION_USER and CURRENT_USER especially when CURRENT_USER is used in a stored procedure or function.
我不得不承认,我不知道企业用户"这个术语是什么意思.
I have to admit that I don't know what the term "enterprise user" means though.
顺便说一句:还有第三个:
Btw: there is a third one:
这篇关于USER()和SYS_CONTEXT('USERENV','CURRENT_USER')有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!