简体   繁体   English

面对错误:表或​​视图不存在

[英]Facing an error : table or view does not exist


I am using insert statement and trying to insert data into the database table. 我正在使用insert语句并尝试将数据插入数据库表。 I am using stored procedures. 我正在使用存储过程。
But I am getting this error while doing so. 但是这样做我得到了这个错误。

Message: ORA-00942: table or view does not exist ORA-06512 消息:ORA-00942:表或视图不存在ORA-06512


I checked if the tables/stored procedures are present or not and everything is in place. 我检查了表/存储过程是否存在,一切都到位。 Also there is no typo in table names or in sp. 表名或sp中也没有拼写错误。 If I run the part of SP from query editor it works fine but when I execute the entire SP it throws an error. 如果我从查询编辑器运行SP的一部分它工作正常,但当我执行整个SP它会抛出一个错误。


I tried the steps provided by Stephen but since I have logged in with the same user/owner when I run Grant command it gives me an error saying 'Cannot Grant/revoke on own'. 我尝试了Stephen提供的步骤,但是因为我在运行Grant命令时使用相同的用户/所有者登录,所以它给出了一个错误,说“不能自行授予/撤销”。
One more addition to this. 还有一个补充。 I have a stored procedure SP1 in which I am using a select statement as 我有一个存储过程SP1,我在其中使用select语句

Select a from table_name where condition;

When I execute this seperately, it returns me some results. 当我单独执行此操作时,它会返回一些结果。 But when I execute sp it gives an error at the same line where it is written. 但是当我执行sp时,它会在写入的同一行给出错误。


Can anyone help me out to resolve this issue. 任何人都可以帮我解决这个问题。 I am using SQL +. 我正在使用SQL +。
Thanks in advance Vijay 在此先感谢Vijay

Justin's answer is correct but let me expand a bit. 贾斯汀的回答是正确的,但让我扩展一下。

Everyone who said that the table doesn't exist didn't read your whole post. 每个说表不存在的人都没有看完你的整篇文章。 Since you are able to: 既然你能够:

If I run the part of SP from query editor it works fine 如果我从查询编辑器运行SP的一部分它工作正常

Obviously the table is there. 桌子显然就在那里。 Obviously you have some access to it. 显然你有一些访问权限。 Otherwise this wouldn't work when it clearly does. 否则,这显然无效。

but when I execute the entire SP it throws an error. 但是当我执行整个SP时,它会抛出一个错误。

This is because Oracle distinguishes between permissions granted directly and those granted via a role. 这是因为Oracle区分了直接授予的权限和通过角色授予的权限。

Say I do this: 说我这样做:

Create Table TABLE_A
Create Role READ_ONLY
Grant Select on TABLE_A to READ_ONLY
Grant READ_ONLY to VIJAY

In a SQL Window/prompt you could query that table without issue. 在SQL窗口/提示符中,您可以毫无问题地查询该表。 So now you need to create a view 所以现在你需要创建一个视图

Create VIJAY.VIEW_A as SELECT * FROM TABLE_A

You'll get the error that TABLE_A does exist. 您将收到TABLE_A确实存在的错误。 Because a view is compiled, like a procedure it runs without any roles. 因为视图是编译的,就像它运行的过程没有任何角色一样。 Since it runs without the READ_ONLY role, it's blind to the fact that TABLE_A exists. 由于它在没有READ_ONLY角色的情况下运行,因此对TABLE_A存在这一事实视而不见。 Now what I need to do is 现在我需要做的是

Grant Select on TABLE_A to VIJAY.

Now that you have a direct permission, you can compile a view or procedure/package that uses that table. 既然您拥有直接权限,则可以编译使用该表的视图或过程/包。

Does the table exist in the schema where the stored procedure exists? 表是否存在于存储过程存在的模式中? If not, the simplest explanation is that the owner of your procedure has been granted access to the table via a role not via a direct grant. 如果没有,最简单的解释是,您的过程的所有者已被授予通过角色而不是通过直接授权访问该表的权限。 A definer's rights stored procedure needs to have direct access to the objects it accesses. 定义者权限存储过程需要直接访问它访问的对象。 A quick way to test this is to disable roles for the session, ie 一种快速测试方法是禁用会话角色,即

SQL> set role none;
SQL> <<execute your query>>

If that generates the error, the problem is the lack of a direct grant. 如果这会产生错误,则问题是缺少直接授权。

In Oracle you can choose if the stored procedure is executed with the rights of the invoker or the definer: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/subprograms.htm#i18574 在Oracle中,您可以选择是否使用调用者或定义者的权限执行存储过程: http//download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/subprograms.htm#i18574

Check if the AUTHID property of the stored procedure is correct and if the resulting user has appropriate permissions. 检查存储过程的AUTHID属性是否正确以及生成的用户是否具有适当的权限。

Well, put very simply, the table that you are trying to insert data into does not exist in the database you are connected to. 好吧,非常简单地说,您尝试插入数据的表在您连接的数据库中不存在。 You need to check both those things (ie what are you connected to, and is the table there and accessible for the user context you are using). 您需要检查这些内容(即您连接到哪些内容,并且是那里的表,并且可以访问您正在使用的用户上下文)。

As Joe Stefanelli said .. there are a lot of possibilities for the error being shown here. 正如Joe Stefanelli所说......这里显示的错误有很多可能性。

Check whether: 检查是否:

  1. You are connecting to the correct Oracle Instance. 您正在连接到正确的Oracle实例。
  2. You have permissions to query or perform processing on table that you are referencing in your query. 您有权在查询中引用的表上查询或执行处理。
  3. There is a difference between ordinary select statements and procedures. 普通的select语句和过程之间存在差异。 Procedures in oracle do not respect the roles assigned to a user; oracle中的过程不尊重分配给用户的角色; rather the permission needs to be explicitly granted to the user. 而是需要将权限明确授予用户。 For more information read the following link ORA-00942 有关更多信息,请阅读以下链接ORA-00942

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM