微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

oracle – USER()和SYS_CONTEXT(‘USERENV’,’CURRENT_USER’)之间有什么区别?

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

原文地址:https://www.jb51.cc/oracle/204957.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐