1. 程式人生 > 其它 >向oracle中批量更新報錯 Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正確結束

向oracle中批量更新報錯 Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正確結束

報錯sql如下:

<update id="updateBatch">
        <foreach collection="list" item="item" index="index" separator=";">
            update ICS_TASK_DETAILS
            set EXE_PEOPLE_ID = #{item.exePeopleId},
                STATUS = #{item.status},
                EXE_TIME = #{item.exeTime}
            
where CAL_TASK_ID = #{item.calTaskId} and TASK_ID = #{item.taskId} </foreach> </update>

修改後sql如下,注意新增begin和;end;

<update id="updateBatch">
        begin
        <foreach collection="list" item="item" index="index" separator=";">
            update
ICS_TASK_DETAILS <set> EXE_PEOPLE_ID = #{item.exePeopleId}, STATUS = #{item.status}, EXE_TIME = #{item.exeTime} </set> where CAL_TASK_ID = #{item.calTaskId} and TASK_ID = #{item.taskId}
</foreach> ;end; </update>

批量更新時,foreach對傳入的資料迭代更新操作,foreach中主要存在collection、item、index、open、separate、close幾個引數:

  collection為指定,指代Dao層介面傳遞的資料型別,分別是list、陣列array和map。

  item:別名,表示集合中每一個元素迭代時的別名,獲取資料時必須指定用別名來指定,如例子中所示,迭代迴圈時,使用item來獲取屬性值。

  index:迭代下標,即迭代過程中的位置。

  open:表示語句以什麼開始。

  separate:表示每次迭代之間以什麼符號作為分割。

  close:表示語句以什麼結束。

 歡迎批評指正。