2012-04-20 25 views
2

去罰款:BadSqlGrammarException通過Spring的JDBC,但使用的SQLDeveloper下面的查詢來測試合併的一切都沒有的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:無效的SQL語句

+1

BadSqlGrammarException被Spring框架拋出。 Spring可能期待一個標準的SELECT語句。 – 2012-04-20 07:35:07

+1

您應該向我們展示執行該語句的代碼 – 2012-04-20 09:58:13

+0

謝謝,我不能直到星期一。我正在使用JdbcTemplate。 queryForLong(String sql,Object [] args),其中sql是合併語句。沒有爲測試目的設置任何參數。不記得任何其他atm,對不起:( – ollo 2012-04-21 00:16:10

回答

1

您可能已經照顧過了,但您可能需要在查詢中轉義單引號。

我也發現,當傳遞一個查詢到Oracle,在我的情況下從SQL Server使用OPENQUERY,分號使查詢失敗,與該Oracle錯誤代碼。

它可能就像刪除語句末尾的分號一樣簡單

相關問題