有时候给一些普通用户授予查询系统对象(例如dynamic performance views)权限时会遇到“ORA-02030: can only select from fixed tables/views”,如下所示:
SQL> grant select on v$session to test;
grant select on v$session to test
*
ERROR at line 1:
ORA-02030: can only select from fixed tables/views
对应的中文提示信息为:
SQL> GRANT SELECT ON v$session TO zbx_monitor;
GRANT SELECT ON v$session TO zbx_monitor
*
第 1 行出现错误:
ORA-02030: 只能从固定的表/视图查询
关于ORA-02030错误介绍如下,也就是对于fixed tables 或fixed views只能进行SELECT查询,不能做SELECT之外的任何操作
[oracle@DB-Server ~]$ oerr ora 2030
02030, 00000, "can only select from fixed tables/views"
// *Cause: An attempt is being made to perform an operation other than
// a retrieval from a fixed table/view.
// *Action: You may only select rows from fixed tables/views.
关于V$ Views的介绍如下:
V$Views
The actual dynamic performance views are identified by the prefix V_$. Public synonyms for these views have the prefix V$. Database administrators and other users should access only the V$ objects, not the V_$ objects.
The dynamic performance views are used by Oracle Enterprise Manager, which is the primary interface for accessing information about system performance. After an instance is started, the V$ views that read from memory are accessible. Views that read data from disk require that the database be mounted, and some require that the database be open.
我们查询发现V$SESSION,V$DBLINK都是fixed views,而且v$这类我们经常查的视图都是v_$视图的同义词。
SQL> SELECT * FROM V$FIXED_TABLE WHERE NAME IN( 'V$SESSION','V$DBLINK');
NAME OBJECT_ID TYPE TABLE_NUM
------------------------------ ---------- ----- ----------
V$SESSION 4294950919 VIEW 65537
V$DBLINK 4294951157 VIEW 65537
SQL>
SQL> COL OWNER FOR A12;
SQL> COL OBJECT_NAME FOR A32;
SQL> COL OBJECT_TYPE FOR A32;
SQL> SELECT OWNER, OBJECT_NAME ,OBJECT_TYPE
2 FROM DBA_OBJECTS
3 WHERE OBJECT_NAME='V$SESSION';
OWNER OBJECT_NAME OBJECT_TYPE
------------ -------------------------------- --------------------------------
PUBLIC V$SESSION SYNONYM
SQL>
SQL> COL TABLE_OWNER FOR A12;
SQL> COL SYNONYM_NAME FOR A20;
SQL> COL TABLE_NAME FOR A16;
SQL> COL DB_LINK FOR A8;
SQL> SELECT * FROM DBA_SYNONYMS WHERE SYNONYM_NAME='V$SESSION';
OWNER SYNONYM_NAME TABLE_OWNER TABLE_NAME DB_LINK
------------ -------------------- ------------ ---------------- --------
PUBLIC V$SESSION SYS V_$SESSION
也就是说V$SESSION这个同义词指向的系统表为SYS.V_$SESSION,所以要授权就应该执行下面SQL语句
SQL>
SQL> GRANT SELECT ON V_$SESSION TO TEST;
Grant succeeded.
如果遇到这样的错误,直接找到对应同义词对应的视图或基表,然后进行授权,如下所示:
SQL> show user;
USER is "SYS"
SQL> grant select on v$dblink to test;
grant select on v$dblink to test
*
ERROR at line 1:
ORA-02030: can only select from fixed tables/views
SQL> COL OWNER FOR A12;
SQL> COL OBJECT_NAME FOR A32;
SQL> COL OBJECT_TYPE FOR A32;
SQL> SELECT OWNER, OBJECT_NAME ,OBJECT_TYPE
2 FROM DBA_OBJECTS
3 WHERE OBJECT_NAME=UPPER('v$dblink');
OWNER OBJECT_NAME OBJECT_TYPE
------------ -------------------------------- --------------------------------
PUBLIC V$DBLINK SYNONYM
SQL> COL TABLE_OWNER FOR A12;
SQL> COL SYNONYM_NAME FOR A20;
SQL> COL TABLE_NAME FOR A16;
SQL> COL DB_LINK FOR A8;
SQL> SELECT * FROM DBA_SYNONYMS WHERE SYNONYM_NAME='V$DBLINK';
OWNER SYNONYM_NAME TABLE_OWNER TABLE_NAME DB_LINK
------------ -------------------- ------------ ---------------- --------
PUBLIC V$DBLINK SYS V_$DBLINK
SQL> grant select on v_$dblink to test;
Grant succeeded.
SQL>
原文始发于微信公众号(DBA闲思杂想录):ORA-02030: can only select from fixed tables/views
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/228048.html