经常遇到需要查找某个对象的定义的情况,下面针对不同类型的对象分别讨论:
一、v$视图和x$视图
普通用户不能访问v$视图:
sql> conn lunar/lunar@test1
已连接。
sql> select * from user_sys_privs;
username privilege admin_option
------------------------------ ---------------------------------------- ------------
sql> select * from user_role_privs;
username granted_role admin_option default_role os_granted
------------------------------ ------------------------------ ------------ ------------ ----------
lunar connect no yes no
lunar resource no yes no
public plustrace no yes no
sql> select count(*) from v$fixed_table;
select count(*) from v$fixed_table
ora-00942: 表或视图不存在
必须授权:
sql> conn /@test1 as sysdba
已连接。
sql> grant select on v_$fixed_table to lunar;
授权成功。
sql> conn lunar/lunar@test1
已连接。
sql>
得到授权的普通用户仍然只能访问v$开头的视图,而不能直接访问v_$开头的视图,
因为实际上v$视图是v_$视图的公有同义词(public synonym)
要想访问v_$必须带上sys.v_$,例如
sql> select count(*) from v$fixed_table;
count(*)
----------
912
sql> select count(*) from v_$fixed_table;
select count(*) from v_$fixed_table
ora-00942: 表或视图不存在
sql> select count(*) from sys.v_$fixed_table;
count(*)
----------
912
sql>
也可以授予用户select any table权限,这样这个用户就可以访问所有的v$视图了:
sql> grant select any table to lunar;
授权成功。
sql> select * from user_role_privs;
username granted_role admin_option default_role os_granted
------------------------------ ------------------------------ ------------ ------------ ----------
lunar connect no yes no
lunar resource no yes no