简体   繁体   中英

How to set the right to see a view in oracle?

I am logged in as user "a" in my oracle database. I can write a query like "Select * from MyView" and I get all results - thats fine.
BUT I can't see the view itself in SqlDeveloper in my View-tree (list), additional to that I am not the owner (which I can see with "Select * from all_views").

How can I change the rights of this view to see "MyVIew" in the tree?

Most likely, there is a synonym (public or private to the A schema) for myView that points at the view that is defined in a different schema. If all_views shows that the owner of the view is B, most likely a DBA has done something like

create synonym a.myView
   for b.myView;

Assuming that is the case, the view definition only exists in the B schema. In SQL Developer, assuming you have access to the view definition, you'd go to "Other Users", not "Views", expand that, choose the B schema, and then look at "Views" in the tree.

If you want the non-GUI way of getting the view definition, you can use the dbms_metadata package , ie

select dbms_metadata.get_ddl( object_type => 'VIEW',
                              name        => 'MYVIEW',
                              schema      => 'B' )
  from dual;

you can not change the right of the view to see it your View-tree (list), because it is not your own object. To have the view in your View-tree (list) you have to create it in your own shema.

I presume you should query all_objects to see what you're actually dealing with. Why? Because of the following example:

Connected as user mike , I'll create a table, grant select on it to public and create a public synonym:

SQL> connect mike/lion
Connected.
SQL> create table test as select 'Littlefoot' name from dual;

Table created.

SQL> create public synonym myview for test;

Synonym created.

SQL> grant select on test to public;

Grant succeeded.

Connect as another user, scott and select from myview :

SQL> connect scott/tiger
Connected.
SQL> select * from myview;

NAME
----------
Littlefoot

Right; it works. Where is it in SQL Developer?

在此处输入图像描述

Aha, it is in public synonyms (I applied filter on name, looking for MYVIEW to skip zillion other public synonyms).

Or, in SQL*Plus:

SQL> select object_name, object_type, owner from all_objects where object_name = 'MYVIEW';

OBJECT_NAME                    OBJECT_TYPE         OWNER
------------------------------ ------------------- ------------------------------
MYVIEW                         SYNONYM             PUBLIC

SQL>

Therefore, I suggest you do the same - query all_objects and you'll know something more about the issue.

@Littlefoot is correct in his answer. You could of course also browse to the view directly via the 'Other Users' portion of the tree, then drill down into the Views.

BUT, you could also just set your Views filter to 'Include Synonyms'

I wrote a story on this topic for TABLES, but it also applies to VIEWS here.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM