加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle – USER()和SYS_CONTEXT(‘USERENV’,’CURRENT_USER’)

发布时间:2020-12-12 15:13:33 所属栏目:百科 来源:网络整理
导读:在Oracle数据库中,以下是什么区别: user() sys_context(‘USERENV’,’CURRENT_USER’) sys_context(‘USERENV’,’SESSION_USER’) 这些也可能与任何“当前用户”相关的值可能吗? sys_context(‘USERENV’,’CURRENT_SCHEMA’) sys_context(‘USERENV’,
在Oracle数据库中,以下是什么区别:

> user()
> sys_context(‘USERENV’,’CURRENT_USER’)
> sys_context(‘USERENV’,’SESSION_USER’)

这些也可能与任何“当前用户”相关的值可能吗?

> sys_context(‘USERENV’,’CURRENT_SCHEMA’)
> sys_context(‘USERENV’,’AUTHENTICATED_IDENTITY’)

我特别感兴趣的是哪些可以改变,哪些可以改变它们,哪些不能改变价值,哪些具有不同的基于连接类型的值,以及哪些(总是)用于登录的模式数据库.

在我的大部分测试中,值总是相同的.唯一的例外是运行以下命令来改变’CURRENT_SCHEMA’:

alter session set current_schema=<SCHEMA>

执行以下结果的错误:

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’)的快捷方式,但是我可以找不到关于此事的文档.

从手册: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions184.htm#SQLRF51825

当前用户

The name of the database user whose privileges are currently active. This may change during the duration of a session to reflect the owner of any active definer’s rights object. When no definer’s rights object is active,CURRENT_USER returns the same value as SESSION_USER. When used directly in the body of a view definition,this returns the user that is executing the cursor that is using the view; it does not respect views used in the cursor as being definer’s rights.

SESSION_USER

The name of the database user at logon. For enterprise users,returns the schema. For other users,returns the database user name. This value remains the same throughout the duration of the session.

因此,在存储过程或函数中使用CURRENT_USER时,SESSION_USER和CURRENT_USER之间存在差异.

我不得不承认,我不知道“企业用户”一词是什么意思.

Btw:有三分之一:

SESSION_USERID

The identifier of the database user at logon.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读