USER()和SYS_CONTEXT('USERENV','CURRENT_USER')有什么区别? [英] What is the difference between USER() and SYS_CONTEXT('USERENV','CURRENT_USER')?

查看:201
本文介绍了USER()和SYS_CONTEXT('USERENV','CURRENT_USER')有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

来自手册,网址为:

其特权当前处于活动状态的数据库用户的名称.在会话期间,此更改可能会有所变化,以反映任何活动的定义者的权限对象的所有者.当没有定义者的权限对象处于活动状态时,CURRENT_USER返回与SESSION_USER相同的值.当直接在视图定义的主体中使用时,这将返回执行使用该视图的游标的用户;它不尊重游标中用作定义者权限的视图.

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之间有一个差异.

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:

登录时数据库用户的标识符.

The identifier of the database user at logon.

这篇关于USER()和SYS_CONTEXT('USERENV','CURRENT_USER')有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆