Java ORA-00942: 表或视图不存在:我如何找到它正在谈论的表或视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/189557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:06:21  来源:igfitidea点击:

ORA-00942: table or view does not exist : How do I find which table or view it is talking about

javasqloraclehibernateora-00942

提问by anjanb

We're running a java/hibernate app going against ORACLE 10g in TESTING. Once in a while, we're seeing this error:

我们在 TESTING 中运行了一个与 ORACLE 10g 对抗的 java/hibernate 应用程序。偶尔,我们会看到此错误:

ORA-00942: table or view does not exist

ORA-00942: 表或视图不存在

Is there a way to find out which table/view(s) ORACLE is talking about ?

有没有办法找出 ORACLE 正在谈论的表/视图?

I know that I can add extra levels of logging in hibernate which will show all the SQL that it executes on ORACLE and then run that SQL to figure out which TABLE/VIEW is missing or missing permission. But given that it is in TESTING/STAGING, that will slow down performance.

我知道我可以在 hibernate 中添加额外的日志级别,这将显示它在 ORACLE 上执行的所有 SQL,然后运行该 SQL 以确定哪个 TABLE/VIEW 缺少或缺少权限。但鉴于它处于 TESTING/STAGING 状态,这会降低性能。

Is there a simple way to narrow down on the Table/View Name ?

有没有一种简单的方法可以缩小表/视图名称的范围?

UPDATE :

更新 :

Just so you know, I don't have control over the Oracle DB Server Environment.
I enabled Hibernate tracing/logging and found a VALID SQL. I even put Wireshark(which is a TCP packet filter) to see what hibernate actually sends and that was a valid SQL. So, why would Oracle complain about it once in a while and NOT always.

请注意,我无法控制 Oracle DB 服务器环境。
我启用了 Hibernate 跟踪/日志记录并找到了一个有效的 SQL。我什至使用 Wireshark(这是一个 TCP 数据包过滤器)来查看 hibernate 实际发送的内容,这是一个有效的 SQL。那么,为什么甲骨文会偶尔而不是总是抱怨它。

采纳答案by Mark

Take a look into the DBA_AUDIT_EXISTS table, when auditing is turned on for Oracle. I believe that Oracle can provide very detailed auditing which you can simply toggle on and off when you like via DB commands, although I dont remember what they are off the top of my head.

当为 Oracle 开启审计时,查看 DBA_AUDIT_EXISTS 表。我相信 Oracle 可以提供非常详细的审计,您可以在喜欢时通过 DB 命令简单地打开和关闭这些审计,尽管我不记得它们是什么。

See: http://docs.oracle.com/cd/B19306_01/network.102/b14266/cfgaudit.htm

请参阅:http: //docs.oracle.com/cd/B19306_01/network.102/b14266/cfgaudit.htm

for some idea (which I just quickly googled for)

一些想法(我只是快速搜索)

回答by EvilTeach

I don't think there is a magic bullet here. It may be a missing table, or a misspelled table name in the query. It may be a privilege issue. You can't really tell without executing the query

我不认为这里有灵丹妙药。它可能是查询中缺少的表或拼写错误的表名。这可能是一个特权问题。不执行查询你真的无法分辨

I suggest you go ahead and instrument your code in such a way that you can turn it on and off. Run it, extract the query, and ship it off to your DBA to resolve.

我建议您继续并以可以打开和关闭它的方式检测您的代码。运行它,提取查询,然后将其发送给您的 DBA 进行解析。

回答by Matthew Watson

This is what I do, appologies to whoever this originally came from, I know I took it from some website, but can't remember where right now.

这就是我所做的,向最初来自谁的道歉,我知道我是从某个网站上获取的,但现在不记得在哪里了。

In preproduction, I have this

在预生产中,我有这个

create table caught_errors (
  dt        date,               
  username  varchar2( 30), -- value from ora_login_user
  msg       varchar2(2000),
  stmt      varchar2(2000)
);


create or replace trigger catch_errors
   after servererror on database
declare
   sql_text ora_name_list_t;
   msg_     varchar2(2000) := null;
   stmt_    varchar2(2000) := null;
begin

  for depth in 1 .. ora_server_error_depth loop
    msg_ := msg_ || ora_server_error_msg(depth);
  end loop;

  for i in 1 .. ora_sql_txt(sql_text) loop
     stmt_ := stmt_ || sql_text(i);
  end loop;

  insert into 
    caught_errors (dt     , username      ,msg ,stmt )
           values (sysdate, ora_login_user,msg_,stmt_);
end;
/

Any time servererror is thrown, its caught and logged to a table, I can then check that table to find the offending queries, and refund them as needed to see the missing table (when you run the query in sqlplus, it will tell you the table)

任何时候 servererror 被抛出,它被捕获并记录到一个表中,然后我可以检查该表以找到有问题的查询,并根据需要退还它们以查看丢失的表(当您在 sqlplus 中运行查询时,它会告诉您桌子)

Note, yes, there is issues with this, eg, what if caught_errors is dropped, or raises an error itself, you could get recursive loop, hence why this only exists in preproduction.

请注意,是的,这存在问题,例如,如果 catch_errors 被删除,或者本身引发错误,您可能会得到递归循环,因此为什么这只存在于预生产中。

回答by aboutstudy

You should check the account, which whether has the permit to access the target table.

您应该检查帐户,该帐户是否具有访问目标表的权限。

回答by meeta lalwani

Please check of the tablespace name is correct if you are facing this issue while importing DB.

如果您在导入数据库时​​遇到此问题,请检查表空间名称是否正确。