转载:PL/SQL中ORA-00942错的进一步研究
2010-02-02 22:40
417 查看
转自:Larry.Yue的
http://miracle.blog.51cto.com/255044/93450
版权声明:
原创作品,允许转载,转载时请务必以超链接形式标明
文章 原始出处
、作者信息和本声明。否则将追究法律责任。http://miracle.blog.51cto.com/255044/93450
对于写某些数据库监控或者编写的过程、函数或包等PL/SQL的对象,如果其中包含ORACLE内部的动态性能试图(DYNAMIC
PERFORMANCE VIEW)和数据字典时,常常会遇到如下错误:
Error: PL/SQL: ORA-00942:
table or view does not exist
查看一下错误原因:
Cause: The
table or view entered does not exist, a synonym that is not allowed here
was used, or a view was referenced where a table is required. Existing
user tables and views can be listed by querying the data dictionary.
Certain privileges may be required to access the table. If an
application returned this message, the table the application tried to
access does not exist in the database, or the application does not have
access to it.
Action: Check each of the following:
the
spelling of the table or view name.
that a view is not specified
where a table is required.
that an existing table or view name
exists.
Contact the database administrator if the table needs to
be created or if user or application privileges are required to access
the table.
Also, if attempting to access a table or view in
another schema, make certain the correct schema is referenced and that
access to the object is granted.
但是大家往往都非常愕然,奇怪呀,明明在SQL/PLUS中是可以直接查询的呀,并且返回了结果。但是为什么在编译过程、函数或者包时有错误出现呢?
其实不然,只能说明我们当前的用户还没有足够的权限。
那好,就直接授权,使得某个用户可以有确定的查询权限:
SQL>
grant select on dba_tablespaces to xxx;
Grant succeeded.
SQL>
grant select on v$session to xxx;
grant select on v$session to asg
*
ERROR
at line 1:
ORA-02030: can only select from fixed tables/views
进行上述操作,可以看到数据字典(DATA DICTIONARY)可以直接授权,而使用了。但是DYNAMIC
PERFORMANCE VIEW却不可以,并且报了ORA-02030的错误。
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$SESSION我的授权是有问题的!对,也就是说V$根本不是个VIEWS(如果你说根本不是TABLES,后面的论述就可以不用看了
-:)) 。
看看ORACLE给出的说明:
V$ Views
The actual
dynamic performance views are identified by the prefix
.
Public synonyms
for these views have the prefix
.
Database administrators and other users should access only the
objects, not the
objects.
很显然,V$可以说是个“同义词”!所以会出现授权的错误。
那么该如何授权呢?对,按照ORACLE给出的规则,按图索骥:
SQL>
grant select on v_$session to XXX;
Grant succeeded.
可以看到授权成功,为了编译成功,我们还要对编写的程序脚本进行轻微的改动,什么?对,就是将V$SESSION改写成SYS.V_$SESSION即
可。
接下来,再想想,如果我们编写的内容,涉及比较多的DATA DICTIONARY或者是DYNAMIC
PERFORMANCE VIEW,我们一个一个授权岂不是很麻烦?
我们可以通过ORACLE预先定义的角色,一次性完成授权:
SQL>
grant select any dictionary to xxx;
Grant succeeded.
这样,我就可以直接使用DATA DICTIONARY和DYNAMIC PERFORMANCE
VIEW。但是,一定要注意,这样的授权对于数据库的安全性来讲是不利的。
------------------------
从ORA-00942开始的问题,我们将问题引申到DYNAMIC PERFORMANCE VIEW和ORACLE
SECURITY等方面,确实很有意思。所以说,对于ORACLE的学习,多动手,多读官方文档,多总结总结确实很重要呀。
技术没有障碍,就看你肯不肯钻 -:)
本文出自 “Be the miracle!
” 博客,请务必保留此出处http://miracle.blog.51cto.com/255044/93450
http://miracle.blog.51cto.com/255044/93450
版权声明:
原创作品,允许转载,转载时请务必以超链接形式标明
文章 原始出处
、作者信息和本声明。否则将追究法律责任。http://miracle.blog.51cto.com/255044/93450
对于写某些数据库监控或者编写的过程、函数或包等PL/SQL的对象,如果其中包含ORACLE内部的动态性能试图(DYNAMIC
PERFORMANCE VIEW)和数据字典时,常常会遇到如下错误:
Error: PL/SQL: ORA-00942:
table or view does not exist
查看一下错误原因:
Cause: The
table or view entered does not exist, a synonym that is not allowed here
was used, or a view was referenced where a table is required. Existing
user tables and views can be listed by querying the data dictionary.
Certain privileges may be required to access the table. If an
application returned this message, the table the application tried to
access does not exist in the database, or the application does not have
access to it.
Action: Check each of the following:
the
spelling of the table or view name.
that a view is not specified
where a table is required.
that an existing table or view name
exists.
Contact the database administrator if the table needs to
be created or if user or application privileges are required to access
the table.
Also, if attempting to access a table or view in
another schema, make certain the correct schema is referenced and that
access to the object is granted.
但是大家往往都非常愕然,奇怪呀,明明在SQL/PLUS中是可以直接查询的呀,并且返回了结果。但是为什么在编译过程、函数或者包时有错误出现呢?
其实不然,只能说明我们当前的用户还没有足够的权限。
那好,就直接授权,使得某个用户可以有确定的查询权限:
SQL>
grant select on dba_tablespaces to xxx;
Grant succeeded.
SQL>
grant select on v$session to xxx;
grant select on v$session to asg
*
ERROR
at line 1:
ORA-02030: can only select from fixed tables/views
进行上述操作,可以看到数据字典(DATA DICTIONARY)可以直接授权,而使用了。但是DYNAMIC
PERFORMANCE VIEW却不可以,并且报了ORA-02030的错误。
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$SESSION我的授权是有问题的!对,也就是说V$根本不是个VIEWS(如果你说根本不是TABLES,后面的论述就可以不用看了
-:)) 。
看看ORACLE给出的说明:
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.
很显然,V$可以说是个“同义词”!所以会出现授权的错误。
那么该如何授权呢?对,按照ORACLE给出的规则,按图索骥:
SQL>
grant select on v_$session to XXX;
Grant succeeded.
可以看到授权成功,为了编译成功,我们还要对编写的程序脚本进行轻微的改动,什么?对,就是将V$SESSION改写成SYS.V_$SESSION即
可。
接下来,再想想,如果我们编写的内容,涉及比较多的DATA DICTIONARY或者是DYNAMIC
PERFORMANCE VIEW,我们一个一个授权岂不是很麻烦?
我们可以通过ORACLE预先定义的角色,一次性完成授权:
SQL>
grant select any dictionary to xxx;
Grant succeeded.
这样,我就可以直接使用DATA DICTIONARY和DYNAMIC PERFORMANCE
VIEW。但是,一定要注意,这样的授权对于数据库的安全性来讲是不利的。
------------------------
从ORA-00942开始的问题,我们将问题引申到DYNAMIC PERFORMANCE VIEW和ORACLE
SECURITY等方面,确实很有意思。所以说,对于ORACLE的学习,多动手,多读官方文档,多总结总结确实很重要呀。
技术没有障碍,就看你肯不肯钻 -:)
本文出自 “Be the miracle!
” 博客,请务必保留此出处http://miracle.blog.51cto.com/255044/93450
相关文章推荐
- PL/SQL中ORA-00942错的进一步研究
- PL/SQL中ORA-00942错的进一步研究 推荐
- PL/SQL Developer登录提示 ORA-12541:TNS:无监听程序(转载)
- ORA-06554: package DBMS_STANDARD must be created before using PL/SQL
- oracle xe client 如何设置 tnsnames.ora(解决无法使用pl/sql developer的问题)
- 使用PL/SQL进行模糊查询时显示错误ORA-00911:无效字符
- PL/Sql循序渐进全面学习教程--Oracle (转载)
- PL/SQL(或者说是Oracle)错误ORA-00972:标识符过长
- PL/SQL 删除外键 ORA-02443: 无法删除约束条件-不存在的约束条件
- <转载>PL/SQL语言基础
- PL/SQL developer的HomeEnd问题(转载)
- PL/SQL连接Oracle错误:ORA-12514、ORA-01034、ORA-27101
- PL/SQL 不能登录,提示错误:ora-12154:tns:无法解析指定的连接标识符
- PL/SQL Developer ORA-01017: 用户名/口令无效; 登录被拒绝 问题解决
- 创建触发器报PL/SQL: ORA-00942: 表或视图不存在
- PL/SQL developer连接oracle出现“ORA-12154:TNS:could not resolve the connect identifier specified”问题的解决
- oracle报PL/SQL:ORA:04044:此处不允许过程、函数、程序包或类型;
- PL/SQL 工具 ORA-12514,监听程序当前无法识别连接描述符
- ora-oo906,powerDesigner中的sql转到pl-sql中提示“缺少左括号”
- PL/SQL Developer 使用技巧【转载】