oracle 作为Sqlplus中的系统,我如何查询另一个用户的表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/122302/
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
As System in Sqlplus, how do I query another user's table?
提问by Tony Andrews
According to select name from system_privilege_map System has been granted:
根据 select name from system_privilege_map 系统已被授予:
SELECT ANY TABLE
...and lots of other * ANY TABLES.
...以及许多其他 * 任何表格。
Plainly running
简单地运行
select * from the_table;
select * from the_table;
...nets the given response:
...网络给定的响应:
ERROR at line 1: ORA-00942: table or view does not exist
第 1 行的错误:ORA-00942:表或视图不存在
I can log in as that user and run the same command just fine.
我可以以该用户身份登录并运行相同的命令就好了。
I'm running under the assumption I should be able to run queries (select in this case) agaisnt a general user's DB table. Is my assumption correct, and if so, how do I do it?
我在假设我应该能够针对一般用户的数据库表运行查询(在这种情况下选择)。我的假设是否正确,如果正确,我该怎么做?
回答by Gazmo
As the previous responses have said, you can prefix the object name with the schema name:
正如之前的回复所说,您可以使用架构名称作为对象名称的前缀:
SELECT * FROM schema_name.the_table;
Or you can use a synonym (private or public):
或者您可以使用同义词(私人或公共):
CREATE (PUBLIC) SYNONYM the_table FOR schema_name.the_table;
Or you can issue an alter session command to set the default schema to the the one you want:
或者您可以发出一个 alter session 命令来将默认架构设置为您想要的架构:
ALTER SESSION SET current_schema=schema_name;
Note that this just sets the default schema, and is the equivalent of prefixing all (unqualified) object names with schema_name
. You can still prefix objects with a different schema name to access an object from another schema. Using SET current_schema
does not affect your privileges: you still have the privileges of the user you logged in as, not the schema you have set.
请注意,这只是设置默认模式,相当于在所有(非限定)对象名称前加上schema_name
. 您仍然可以使用不同的架构名称作为对象的前缀,以从另一个架构访问对象。使用SET current_schema
不会影响您的权限:您仍然拥有登录用户的权限,而不是您设置的架构。
回答by Tony Andrews
If the_table is owned by user "some_user" then:
如果 the_table 归用户“some_user”所有,则:
select * from some_user.the_table;
回答by cagcowboy
You need to do:
你需要做:
SELECT * FROM schema_name.the_table;
Or use SYNONYMs...
或使用同义词...
CREATE SYNONYM the_table FOR schema_name.the_table;