【问题标题】:BadSqlGrammarException through Spring-JDBC but not in SQLDeveloperBadSqlGrammarException 通过 Spring-JDBC 但不在 SQLDeveloper 中
【发布时间】:2012-05-01 18:59:46
【问题描述】:

在 SQLDeveloper 中使用以下查询来测试合并一切正常:

merge into proj.person_registry pr 
using ( 
select null as id, 
'69696696553' as code, 
'TESTYMC' as name, 
'WHATEVER' as firstname, 
'M' as cl_gender, 
'E' as cl_status, 
null as birth_date, 
null as death_date, 
null as citizen_country_code, 
null as country_code, 
null as location_code, 
null as zip, 
'SOMETOWN' as aadress, 
null as date_updated, 
null as date_created, 
null as aadress_date 
from dual) t on (pr.code = t.code) 
when matched then update set 
pr.name                 = t.name, 
pr.firstname            = t.firstname, 
pr.cl_gender            = t.cl_gender, 
pr.cl_status            = t.cl_status, 
pr.birth_date           = t.birth_date, 
pr.death_date           = t.death_date, 
pr.citizen_country_code = t.citizen_country_code, 
pr.country_code         = t.country_code, 
pr.location_code        = t.location_code, 
pr.zip                  = t.zip, 
pr.aadress              = t.aadress, 
pr.aadress_date         = t.aadress_date 
when not matched then 
insert values (t.id, t.code, t.name, t.firstname, t.cl_gender, t.cl_status, t.birth_date, t.death_date, t.citizen_country_code, t.country_code, t.location_code, t.zip, t.aadress, t.date_created, t.date_updated, t.aadress_date);

但是尝试使用 jdbc 在我的代码中执行它会引发 BadSqlGrammarException,原因如下:java.sql.SQLException: ORA-00900: invalid SQL statement

【问题讨论】:

  • BadSqlGrammarException 由 Spring 框架引发。 Spring 可能期待一个标准的 SELECT 语句。
  • 您应该向我们展示执行该语句的代码
  • 谢谢,我不能到星期一。我正在使用 JdbcTemplate。 queryForLong(String sql, Object[] args) ,其中 sql 是合并语句。甚至没有为测试目的设置任何参数。不记得其他ATM了,对不起:(

标签: sql spring oracle-sqldeveloper ora-00900


【解决方案1】:

您可能已经满足了这一点,但您可能需要转义查询中的单引号。

我还发现,在将查询传递给 Oracle 时,在我的例子中,使用 OPENQUERY 从 SQL Server 传递查询时,分号会使查询失败,并显示该 Oracle 错误代码。

这可能就像从语句末尾删除分号一样简单

【讨论】:

    猜你喜欢
    • 2019-01-25
    • 2016-07-04
    • 2022-01-20
    • 1970-01-01
    • 2011-04-10
    • 2018-12-04
    • 1970-01-01
    • 2020-03-25
    • 2018-10-05
    相关资源
    最近更新 更多