问题描述:
在一个dba用户下的存储过程中需要使用v$的视图,有ORA-02030报错。
直接执行如下语句,可以正常执行:
insert into CURSORNUM_Rui select * from (select * from (select sid,value
from v$sesstat a,v$statname bwhere a.statistic#=b.statistic#
and name='opened cursors current' order by 2 DESC)a
where rownum<2);
接下来编辑成存储过程,如下:
create or replace procedure Rec_CursorNum is
begininsert into CURSORNUM_Rui select * from (select * from (select sid,value
from v$sesstat a,v$statname bwhere a.statistic#=b.statistic#
and name='opened cursors current' order by 2 DESC)a
where rownum<2);end;
显示该存储过程不可用:
查看具体信息:
可以看到是由于该DBA用户没有对v$sesstat ,v$statname这两个视图的select权限。
所以,现尝试直接赋权,而不是通过角色赋权。
$ sqlplus / as sysdba
SQL> grant select on v$sesstat to rui;
grant select on v$sesstat to rui*
ERROR at line 1:
ORA-02030: can only select from fixed tables/views
发现有ORA-02030报错,处理方式如下:
select TABLE_NAME from dba_synonyms t where t.synonym_name = 'V$SESSTAT'; --结果为V_$SESSTAT
select TABLE_NAME from dba_synonyms t where t.synonym_name = 'V$STATNAME';--结果为V_$STATNAME
再次执行赋权语句:
SQL> grant select on V_$SESSTAT to rui;Grant succeeded.SQL> grant select on V_$STATNAME to rui;Grant succeeded.
现已成功赋权。
接下来删除之前的存储过程Rec_CursorNum,然后重新创建。
ok啦!