简体   繁体   English

查询在SQL * Plus中有效,但在JDBC中失败,并带有ORA-00911异常

[英]A query works in SQL*Plus but fails in JDBC with an ORA-00911 exception

I'm trying to track the amount of redo being generated during a database session with the following query: 我正在尝试使用以下查询跟踪在数据库会话期间生成的重做量:

SELECT a.name, b.VALUE
  FROM v$statname a, v$mystat b
  WHERE a.statistic# = b.statistic# AND a.name = 'redo size';

This query works directly in SQL*Plus and Toad, but I get an ORA-00911 exception using JDBC, and I've narrowed it down to the "statistic#" column name. 该查询直接在SQL * Plus和Toad中工作,但是我使用JDBC得到了ORA-00911异常,并且将其范围缩小为“ statistic#”列名。

How do I get around this? 我该如何解决?

The column name statistic# is not the problem. 列名称statistic#不是问题。

My bet is that you also send the terminating ; 我敢打赌,您也要发送终止消息; from inside your Java program. 从您的Java程序内部。

But you may not include the the ; 但是您可能不包括; when executing a SQL statement through JDBC (at least not in Oracle and some other DBMS). 通过JDBC执行SQL语句时(至少不是在Oracle和其他一些DBMS中)。

Remove the ; 删除; from your SQL String and it should be fine. 从您的SQL字符串,应该没问题。

将其用双引号引起来-这应该使您可以在Oracle中将字段称为任何内容

Switch on JDBC logging, check your driver documentation for how to do this. 打开JDBC日志记录,查看驱动程序文档以了解操作方法。 In the JDBC log you see the actual statement prepared and executed in the DB. 在JDBC日志中,您会看到在数据库中准备并执行的实际语句。 This eliminates one possible cause for the error. 这消除了导致错误的一种可能原因。

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

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