以用户身份连接时在 Oracle 数据库中收集 dba_users 信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9881126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:41:18  来源:igfitidea点击:

gather dba_users information in Oracle database when connected as a user

databaseoracle

提问by DCookie

I am new to Oracle database. I see that if I connect as sysuser, I can do

我是 Oracle 数据库的新手。我看到如果我以sys用户身份连接,我可以做到

select * from dba_users;

select * from dba_users;

But once I have done conn nonsys@dbid, I can no longer do that; I will get an error saying

但是一旦我做了conn nonsys@dbid,我就不能再那样做了;我会收到一条错误消息

ORA-00942: table or view does not exist

ORA-00942: table or view does not exist

select * from sys.dba_users;is not working either.

select * from sys.dba_users;也不工作。

Could you please explain why this is and how I can do select * from dba_users;after connected as a non-sys user?

您能否解释一下为什么会这样以及select * from dba_users;在以非系统用户身份连接后我该怎么做?

Also, disconnectmakes me totally disconnected; is it possible to only "exit" current user and back to sysin sqlplus and if so, how to do that?

此外,disconnect让我完全断开连接;是否可以只“退出”当前用户并返回到syssqlplus 中,如果可以,该怎么做?

回答by DCookie

The DBA_* views in Oracle contain information about ALL objects in the database regardless of ownership. Only administrative accounts have access to these views by default. This is done for security reasons. In order to have a "normal" user gain access to these views, they must be granted access to them, either directly on a per-view basis, or globally through such system privileges as SELECT ANY TABLE (not recommended). Better to grant access to the actual DBA_ view the user really needs. Generally, the ALL_ views will give a typical user all the information they require.

Oracle 中的 DBA_* 视图包含有关数据库中所有对象的信息,而不管其所有权如何。默认情况下,只有管理帐户才能访问这些视图。这样做是出于安全原因。为了让“普通”用户获得对这些视图的访问权限,他们必须被授予对它们的访问权限,无论是直接在每个视图的基础上,还是通过诸如 SELECT ANY TABLE(不推荐)之类的系统权限全局访问。最好授予对用户真正需要的实际 DBA_ 视图的访问权限。通常,ALL_ 视图将为典型用户提供他们需要的所有信息。

To leave the current user session and connect as another user, use the CONNECT command:

要离开当前用户会话并以另一个用户身份连接,请使用 CONNECT 命令:

CONNECT sys/pw as sysdba

EDIT:

编辑:

The owner of an object can grant access to any of their objects to another user or role via the GRANT command:

对象的所有者可以通过GRANT 命令将其任何对象的访问权限授予另一个用户或角色

GRANT SELECT ON dba_users TO nonsys;

Performed as the user SYS, this would grant select access to the dba_users view to the user nonsys.

作为用户 SYS 执行,这将授予用户 nonsys 对 dba_users 视图的选择访问权限。

Once the grant is performed, the user nonsys will be able to select from this view via the SELECT statement:

执行授权后,用户 nonsys 将能够通过 SELECT 语句从此视图中进行选择:

SELECT * FROM dba_users;