Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle: Creating view across schemas?

I'm trying to create a view, and have distilled the problem down to the inability to create a view that references tables from a different schema.

For example, I can do:

select count(*) from otherschema.othertable;

and I can do:

create view foo as select count(*) as bar from oneofmytables;

But if I try:

create view foo as select count(*) as bar from otherschema.othertable;

I get an "insufficient privileges" error. What additional privileges do I need?

like image 496
chris Avatar asked Jan 31 '11 19:01

chris


People also ask

Can we CREATE VIEW from another view in Oracle?

Creating Views Database views are created using the CREATE VIEW statement. Views can be created from a single table, multiple tables or another view. To create a view, a user must have the appropriate system privilege according to the specific implementation.

How are views created in Oracle?

Answer: A VIEW in Oracle is created by joining one or more tables. When you update record(s) in a VIEW, it updates the records in the underlying tables that make up the View. So, yes, you can update the data in an Oracle VIEW providing you have the proper privileges to the underlying Oracle tables.

What is Oracle Force view?

Force View does forces the creation of a View even when the View will be invalid. NoForce Is the default. Code. CREATE FORCE VIEW.

Why do we create views in Oracle?

A view is a virtual table because you can use it like a table in your SQL queries. Every view has columns with data types so you can execute a query against views or manage their contents (with some restrictions) using the INSERT , UPDATE , DELETE , and MERGE statements. Unlike a table, a view does not store any data.


2 Answers

Do you have the grant to the other user's table directly? Or is it via a role? You will need the privilege to be granted directly in order to create an object (view, procedure, etc.) that references the other table. As a quick test, in SQL*Plus

SQL> set role none;
SQL> select count(*) from otherschema.othertable;

If that fails, then the problem is that you have been granted privileges on the table via a role.

like image 91
Justin Cave Avatar answered Oct 12 '22 11:10

Justin Cave


I guess you have been given select right on otherschema.othertable via a role not via a direct grant.

If this is the case, you should connect as otheruser and then do a grant select on othertable to <your-schema>.

like image 23
René Nyffenegger Avatar answered Oct 12 '22 12:10

René Nyffenegger