HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

access all_mview or user_mviews from app code

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
all_mviewuser_mviewsappcodefromaccess

Problem

I need to access the user_mviews or all_mviews table to get meta information about materialized view in my app. Which grants are necessary to read the user_mviews table?

Solution

by default all users can read the user_mviews and all_mviews views since the SELECT right is granted to public:

SQL> SELECT grantee, privilege, table_name
  2    FROM dba_tab_privs
  3   WHERE table_name IN ('USER_MVIEWS', 'ALL_MVIEWS');

GRANTEE  PRIVILEGE  TABLE_NAME
-------- ---------- ------------
PUBLIC   SELECT     USER_MVIEWS
PUBLIC   SELECT     ALL_MVIEWS


If for some reason this grant has been removed, you would need to regrant the rights to either public or a specific user (with a DBA account):

GRANT SELECT ON user_mviews TO ;


Edit: By definition, USER_MVIEWS describes materialized views owned by the current user while ALL_MVIEWS describes the materialized views accessible to the current user (the user needs to be granted SELECT on the mview either directly or through a role).

Code Snippets

SQL> SELECT grantee, privilege, table_name
  2    FROM dba_tab_privs
  3   WHERE table_name IN ('USER_MVIEWS', 'ALL_MVIEWS');

GRANTEE  PRIVILEGE  TABLE_NAME
-------- ---------- ------------
PUBLIC   SELECT     USER_MVIEWS
PUBLIC   SELECT     ALL_MVIEWS
GRANT SELECT ON user_mviews TO <user>;

Context

StackExchange Database Administrators Q#2589, answer score: 5

Revisions (0)

No revisions yet.