Skip to Main Content
  • Questions
  • Unable to create views on tables that have grants using roles

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, uday.

Asked: October 19, 2023 - 1:22 pm UTC

Last updated: October 26, 2023 - 12:32 pm UTC

Version: 19.0.1

Viewed 1000+ times

You Asked

Hi Tom,

I have 2 schemas
1. Sysadmin
2. Esourcing
And sysadmin has default role of sysadm_role
So I have a table in esourcing table
So below is my grant

Grant select on esourcing.table1 to sysadm_role;
Create view sysadmin.view1 as
Select * from esourcing.table1;


But I am getting below error can you tell me what went wrong here.

Error:
ORA 00942 TABLE OR VIEW DOES NOT EXIST

and Chris said...

From the docs:

The owner of the schema containing the view must have the privileges necessary to either select (READ or SELECT privilege), insert, update, or delete rows from all the tables or views on which the view is based. The owner must be granted these privileges directly, rather than through a role.

https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/CREATE-VIEW.html

So you can't use roles to do this, only direct grants.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library