更新使用2个表不能从批处理

时间:2017-01-23 13:47:27

标签: sql oracle sql-update spring-batch

我需要使用另一个表的列中的值之和来更新表。

我正在使用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)

因此,我需要更新CI21_ENCOF7 EFFET_COMMERCECI21_CDPRRT '036993'CI23_CUMTCR EFFET_COMMERCE_23_TMPCI2X_IDCONT {1}}具有相同的<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>

在SQLDeveloper上,此查询似乎工作正常。 但是当我在Spring Batch中使用它时,我收到了错误:

  

GRAVE:在job effetCommercialeBeanJob中遇到执行step injectionDesDonnees的错误   org.springframework.jdbc.BadSqlGrammarException:PreparedStatementCallback;糟糕的SQL语法[

     

插入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)   值(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)                 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 =   &#39; 036993&#39; 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命令没有&#39;正确结束)

知道可能出现什么问题吗?

编辑: 这是来自job-report.xml的bean:

 <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>

来自job-report.xml的compositeWriter bean:

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;
    }

}

和compositeWriter java类:

(function($){
  $(function(){
       // rest of the code here
  })
})(jQuery)

1 个答案:

答案 0 :(得分:0)

最后,由于我最后要执行UPDATE,我最终在执行作业后才这样做,因为我对春季批次一无所知,这是更简单的解决方案我:

execution = jobLauncher.run(job, new JobParameters(jobParametersMap));

                DataSource datasource = (DataSource) context.getBean("dataSource");
                Connection conn = datasource.getConnection();
                PreparedStatement query = conn.prepareStatement("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)");
                query.executeQuery();