我需要使用另一個表的列的值的總和來更新表。使用2個表的更新不能從批處理工作
我正在使用Oracle數據庫。
我有以下查詢:
UPDATE EFFET_COMMERCE
SET EFFET_COMMERCE.CI21_ENCOF7 = (SELECT SUM(EFFET_COMMERCE_23_TMP.CI23_CUMTCR) FROM
EFFET_COMMERCE_23_TMP WHERE EFFET_COMMERCE.CI2X_IDCONT = EFFET_COMMERCE_23_TMP.CI2X_IDCONT)
WHERE EFFET_COMMERCE.CI21_CDPRRT = '036993'
AND EXISTS (SELECT SUM(EFFET_COMMERCE_23_TMP.CI23_CUMTCR) FROM
EFFET_COMMERCE_23_TMP WHERE EFFET_COMMERCE.CI2X_IDCONT = EFFET_COMMERCE_23_TMP.CI2X_IDCONT)
所以我需要更新從EFFET_COMMERCE
表CI21_ENCOF7
的列,其中CI21_CDPRRT
是'036993'
與具有相同CI2X_IDCONT
的EFFET_COMMERCE_23_TMP
的CI23_CUMTCR
值的總和。
在SQLDeveloper上,此查詢似乎正常工作。 但是當我在Spring Batch的使用它,我發現了錯誤:
墳墓遇到執行步驟injectionDesDonnees在工作effetCommercialeBeanJob org.springframework.jdbc.BadSqlGrammarException錯誤:PreparedStatementCallback;糟糕的SQL語法[
INSERT INTO EFFET_COMMERCE(CI10_DATRAI,CI2X_IDCGIC,CI2X_IDCONT,CI20_CDDV,CI21_CDPRRT,CI21_CDEPR3,CI21_DACRR7,CI21_DAFEPN,CI21_DADAU8,CI21_DAFNAU,CI21_MTAUTN,CI21_DADTAP,CI21_DAFIAB,CI21_MTAUTP,CI21_ENCOF7,CI21_DAECPN,CI21_STCOLE) 值(? (SELECT SUM(EFFET_COMMERCE_23_TMP.CI23_CUMTCR)FROM(from gamasutra)FROM(from gamasutra)FROM(from gamasutra)FROM(from gamasutra)FROM(from gamasutra)FROM EFFET_COMMERCE_23_TMP WHERE EFFET_COMMERCE.CI2X_IDCONT = EFFET_COMMERCE_23_TMP.CI2X_IDCONT)WHERE EFFET_COMMERCE.CI21_CDPRRT = '036993' AND EXISTS(SELECT SUM(EFFET_COMMERCE_23_TMP.CI23_CUMTCR) FROM EFFET_COMMERCE_23_TMP WHERE EFFET_COMMERCE.CI2X_IDCONT = EFFET_COMMERCE_23_TMP.CI2X_IDCONT) ];嵌套的例外是java.sql.BatchUpdateException:ORA-00933:LA COMMANDE SQL NE SE termine PAS correctement
(SQL命令犯規」端正確)
任何想法可能是錯誤的?
編輯: 這裏是從作業-report.xml將豆:
<bean id="insertItemWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
insert into EFFET_COMMERCE(CI10_DATRAI,CI2X_IDCGIC,CI2X_IDCONT,CI20_CDDV,CI21_CDPRRT,CI21_CDEPR3,CI21_DACRR7,CI21_DAFEPN,CI21_DADAU8,CI21_DAFNAU,CI21_MTAUTN,CI21_DADTAP,CI21_DAFIAB,CI21_MTAUTP,CI21_ENCOF7,CI21_DAECPN,CI21_STCOLE) values (:CI10_DATRAI, :CI2X_IDCGIC, :CI2X_IDCONT, :CI20_CDDV, :CI21_CDPRRT, :CI21_CDEPR3, :CI21_DACRR7, :CI21_DAFEPN, :CI21_DADAU8, :CI21_DAFNAU, :CI21_MTAUTN, :CI21_DADTAP, :CI21_DAFIAB, :CI21_MTAUTP, :CI21_ENCOF7, :CI21_DAECPN, :CI21_STCOLE);
UPDATE EFFET_COMMERCE SET EFFET_COMMERCE.CI21_ENCOF7 = (SELECT SUM(EFFET_COMMERCE_23_TMP.CI23_CUMTCR) FROM EFFET_COMMERCE_23_TMP WHERE EFFET_COMMERCE.CI2X_IDCONT = EFFET_COMMERCE_23_TMP.CI2X_IDCONT) WHERE EFFET_COMMERCE.CI21_CDPRRT = '036993' AND EXISTS (SELECT SUM(EFFET_COMMERCE_23_TMP.CI23_CUMTCR) FROM EFFET_COMMERCE_23_TMP WHERE EFFET_COMMERCE.CI2X_IDCONT = EFFET_COMMERCE_23_TMP.CI2X_IDCONT);
]]>
</value>
</property>
<!-- It will take care matching between object property and sql name parameter -->
<property name="itemSqlParameterSourceProvider">
<bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
</bean>
從工作-report.xml將在compositeWriter豆:
<bean id="compositeWriter" class="com.socgen.cie.config.CompositeWriter" scope="step">
<property name="datRaiP" value="#{jobParameters['datRaiP']}" />
<property name="delegate1" ref="insert_20_ItemWriter" />
<property name="delegate2" ref="insert_21_ItemWriter" />
<property name="delegate3" ref="insert_23_ItemWriter" />
</bean>
而且compositeWriter java類:
public class CompositeWriter implements ItemWriter<EffetCommercialeBean> {
ItemWriter<EffetCommercialeBean> itemWriter1;
ItemWriter<EffetCommercialeBean> itemWriter2;
ItemWriter<EffetCommercialeBean> itemWriter3;
private Date datRaiP;
public void write(List<? extends EffetCommercialeBean> items) throws Exception {
List<EffetCommercialeBean> inserts_20 = new ArrayList<EffetCommercialeBean>();
List<EffetCommercialeBean> inserts_21 = new ArrayList<EffetCommercialeBean>();
List<EffetCommercialeBean> inserts_23 = new ArrayList<EffetCommercialeBean>();
Date date = getDatRaiP();
for(EffetCommercialeBean re : items) {
// if(re.getCI10_DATRAI()!=null){
// date = dateFinDuMois(re.getCI10_DATRAI());
// }
re.setCI10_DATRAI(date);
if("20".equals(re.getPattern())) {
inserts_20.add(re);
}
if("21".equals(re.getPattern())) {
inserts_21.add(re);
}
if("23".equals(re.getPattern())) {
inserts_23.add(re);
}
}
itemWriter1.write(inserts_20);
itemWriter2.write(inserts_21);
itemWriter3.write(inserts_23);
}
public void setDelegate1(ItemWriter<EffetCommercialeBean> itemWriter){
this.itemWriter1 = itemWriter;
}
public void setDelegate2(ItemWriter<EffetCommercialeBean> itemWriter) {
this.itemWriter2 = itemWriter;
}
public void setDelegate3(ItemWriter<EffetCommercialeBean> itemWriter) {
this.itemWriter3 = itemWriter;
}
public Date getDatRaiP() {
return datRaiP;
}
public void setDatRaiP(Date datRaiP) {
this.datRaiP = datRaiP;
}
}
您使用了不正確的Spring方法來執行更新。發佈您的Java代碼。解釋器將你的SQL語句轉換爲INSERT INTO –
剛剛編輯了這篇文章,現在我猜我需要在'job-report.xml'中爲更新創建一個特定的bean?我想我還需要有一個compositeUpdater java類? – Ellone