Oracle 创建视图问题

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

Oracle Create View issue

sqloracleviewgrantora-00942

提问by ntsue

Hey guys. So, I am logged in as the dba account and I want to create a view in User1's schema, but selecting data from User2's.

大家好。所以,我以 dba 帐户登录,我想在 User1 的架构中创建一个视图,但从 User2 的模式中选择数据。

I used the following query:

我使用了以下查询:

CREATE OR REPLACE VIEW User1.NewView (Column1) AS
SELECT DISTINCT Column1 FROM User2.Table

and I get the following error:

我收到以下错误:

SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

To resolve this I had to grant select access to User1 on User2.Table. Is there a way to do this without having to grant access, since I am already logged in as the dba? Thanks guys!

为了解决这个问题,我必须在 User2.Table 上授予对 User1 的选择访问权限。有没有办法在不必授予访问权限的情况下执行此操作,因为我已经以 dba 身份登录?谢谢你们!

回答by OMG Ponies

Yes, you have (and always should) to explicitly grant access to objects in another schema.

是的,您必须(并且总是应该)明确授予对另一个架构中的对象的访问权限。

GRANT SELECT ON user2.table TO user1

Though you're logged in as "the dba account" (SYS, I'm assuming), the CREATE statement is for the user1 schema specifically.

尽管您以“dba 帐户”(我假设为 SYS)身份登录,但 CREATE 语句专门针对 user1 架构。

回答by Gary Myers

You can do CREATE OR REPLACE FORCE VIEW ...

您可以创建或替换力视图...

That will create the view despite the lack of privileges, but the view would not be usable unless the privileges are granted. It is a solution that can be useful if privileges will be granted later (eg in some automated build script).

尽管没有特权,这将创建视图,但除非授予特权,否则视图将无法使用。如果稍后授予权限(例如在某些自动构建脚本中),这是一个很有用的解决方案。

回答by user2083954

Probably because you do not have access to the table or view

可能是因为您无权访问表或视图

Query grant privileges on object to user;

查询授予用户对象的权限;