java.sql.SQLException: ORA-00936: missing expression
2011-08-18 11:28
357 查看
java.sql.SQLException: ORA-00936: missing expression
JDBC is very straightforward, create a sql and execute it. The sql created can be static or dynamic and based on the business logic the sql can be be complicated as
well. In case of Oracle being used as a database, Oracle provided a unique
error code that helps to narrow down the issue quickly. Lets look at one such
error code
ORA-00936: missing expression
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:894)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:984)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2885)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2926)
at com.p6spy.engine.logging.P6LogPreparedStatement.executeQuery(P6LogPreparedStatement.java:172)
at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:124)
For example, a SELECT statement passed on to the JDBC may be
- without a list of columns or
- expressions or
- with an incomplete expression.
This error can also occur if any SQL
reserved
word is used.
So check the sql in code, sometimes the sql is created dynamically so closely review code to find out what is missing and try. If you can find the actual sql try execute from a SQL Client like SQL Developer at times it would give the location of the error
in sql. If you are using P6SpyLog Driver then you can get the actual sql that is executed from the p6spy log file.
例题分析:
错误写法
/**
* 插入记录
*/
private String SQL_INSERT = "INSERT INTO table1 " +
"( ID ,NAME)" +
" VALUES " +
"( select table1sequence.nextval,? )";
正确写法
/**
* 插入记录
*/
private String SQL_INSERT = "INSERT INTO table1 " +
"( ID ,NAME)" +
" VALUES " +
"( table1sequence.nextval,? )";
JDBC is very straightforward, create a sql and execute it. The sql created can be static or dynamic and based on the business logic the sql can be be complicated as
well. In case of Oracle being used as a database, Oracle provided a unique
error code that helps to narrow down the issue quickly. Lets look at one such
error code
ORA-00936: missing expression
Issue
The following exception can be seen in the logs with a very specific ORA code as show below:java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:894)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:984)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2885)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2926)
at com.p6spy.engine.logging.P6LogPreparedStatement.executeQuery(P6LogPreparedStatement.java:172)
at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:124)
Resolution
Basically in the case a required part of a where clause or an expression has been omitted/missing for the sql and OracleFor example, a SELECT statement passed on to the JDBC may be
- without a list of columns or
- expressions or
- with an incomplete expression.
This error can also occur if any SQL
reserved
word is used.
So check the sql in code, sometimes the sql is created dynamically so closely review code to find out what is missing and try. If you can find the actual sql try execute from a SQL Client like SQL Developer at times it would give the location of the error
in sql. If you are using P6SpyLog Driver then you can get the actual sql that is executed from the p6spy log file.
例题分析:
错误写法
/**
* 插入记录
*/
private String SQL_INSERT = "INSERT INTO table1 " +
"( ID ,NAME)" +
" VALUES " +
"( select table1sequence.nextval,? )";
正确写法
/**
* 插入记录
*/
private String SQL_INSERT = "INSERT INTO table1 " +
"( ID ,NAME)" +
" VALUES " +
"( table1sequence.nextval,? )";
相关文章推荐
- java.sql.sqlexception:ora-00936:缺失表达式
- java.sql.sqlexception:ora-00936:缺失表达式
- java.sql.SQLException: ORA-01017: invalid username/password; logon denied
- [异常解决]java.sql.SQLException: ORA-00947
- Orcale对DBUtils不支持模糊查询(Exception:java.sql.SQLException: ORA-00904)的原因与解决
- java.sql.SQLException: ORA-00942: 表或视图不存在
- quartz1.5.0链接数据库报错java.sql.SQLException: ORA-00904: "PRIORITY": 无效的标识符
- Caused by: java.sql.SQLException: ORA-00911: 无效字符
- java.sql.SQLException: ORA-00904: "THIS_"."NAME": 标识符无效?
- java.sql.SQLException: ORA-01000: 超出打开游标的最大数的原因和解决方案
- java.sql.SQLException:ORA-01861:文字和格式字符串不匹配
- java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("LVJIAN"."T_ITEMS"."ITEM_NAME")
- java.sql.SQLException: ORA-01436: 用户数据中的 CONNECT BY 循环
- java.sql.SQLException: ORA-28040: No matching authentication protocol 问题
- java.sql.SQLException: ORA-01000: 超出打开游标的最大数
- java.sql.SQLException: ORA-01000: maximum open cursors exceeded
- java.sql.SQLException: ORA-00911: invalid character
- java.sql.SQLException: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
- java.sql.SQLException: ORA-01000: 超出打开游标的最大数
- java.sql.SQLException: ORA-01000: 超出打开游标的最大数