1. 程式人生 > >ORA-02030: can only select from fixed tables/views

ORA-02030: can only select from fixed tables/views

有時候給一些普通使用者授予查詢系統物件(例如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

 

 

 

關於ORA-02030錯誤介紹如下,也是就是對於fixed tables 或fixed views只能進行SELECT查詢,不能做SELECT之外的任何操作

 

[[email protected] ~]$ 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

 

 

所以要授權就應該執行下面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> 

 

clip_image001