Oracle Create View issue

2019-04-06 22:38发布

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.

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!

3条回答
啃猪蹄的小仙女
2楼-- · 2019-04-06 23:18

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

查看更多
女痞
3楼-- · 2019-04-06 23:21

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

Query grant privileges on object to user;

查看更多
Fickle 薄情
4楼-- · 2019-04-06 23:31

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.

查看更多
登录 后发表回答