以下 Oracle 查询在我的数据库客户端 PL/SQL Developer 中运行正常,并返回 1 个结果。
在我的 Java 应用程序中通过 NamedParameterJdbcTemplate (SpringJDBC) 运行它时,我得到
java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
不可能有任何空间问题或任何明显的问题,因为这个精确的查询是在 PL/SQL 中完成的。
private static final String SELECT1 =
" SELECT COUNT(*) "
" FROM table1 t1, table2 t2 " +
" WHERE t1.received_date > TRUNC(sysdate - 1) " +
" AND t1.received_date < TRUNC(sysdate) " +
" AND t1.type IN ('TYPE1', 'TYPE2') " +
" AND t2.received_num = t1.received_num; ";
public int getSelect1() {
HashMap<String,Object> paramMap = new HashMap<String,Object>();
return jdbcTemplate.queryForObject(SELECT1, paramMap, Integer.class);
}
最佳答案
我认为您不需要带有 sql 字符串的分号。
private static final String SELECT1 =
" SELECT COUNT(*) " +
" FROM table1 t1, table2 t2 " +
" WHERE t1.received_date > TRUNC(sysdate - 1) " +
" AND t1.received_date < TRUNC(sysdate) " +
" AND t1.type IN ('TYPE1', 'TYPE2') " +
" AND t2.received_num = t1.received_num ";
关于Spring JDBC 给出 ORA-00933 : SQL command not properly ended But Query Runs OK in DB Client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32894997/