从另一个用户访问 Oracle 模式对象而不使用用户前缀

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9739190/
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:40:17  来源:igfitidea点击:

Access Oracle schema objects from another user without using user prefix

oracleoracle10goracle11g

提问by Jon

I have a a user that has a lot of tables against their account. Lets says UserA. I can do SELECT * FROM TABLEand all is fine. If I login in as a different user, UserB, but make this user a readonly connection I cannot access the table, I have to use SELECT * FROM UserA.TABLE

我有一个用户,他们的帐户有很多表。让我们说 UserA。我可以SELECT * FROM TABLE,一切都很好。如果我以不同的用户 UserB 登录,但将此用户设为只读连接,我无法访问该表,我必须使用SELECT * FROM UserA.TABLE

Is there a way in Oracle somewhere to allow UserB access to UserA's tables without having to put the user prefix before the table name?

在 Oracle 某处有没有办法允许 UserB 访问 UserA 的表,而不必将用户前缀放在表名之前?

回答by a_horse_with_no_name

After logging in as UserB, run the following statement:

以 UserB 身份登录后,运行以下语句:

ALTER SESSION SET current_schema = UserA;

After that you don't have to prefix your table names.

之后,您不必为表名添加前缀。

You can create a logon trigger that does this automatically if you don't want to run it manually.

如果您不想手动运行,您可以创建一个自动执行此操作的登录触发器。

回答by markblandford

You can also do this by creating a Synonym on the table:

您也可以通过在表上创建 Synonym 来做到这一点:

CREATE SYNONYM TABLE FOR UserA.TABLE;