Java Mybatis 多次更新语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33372524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Mybatis multiple update statements
提问by d-man
Java Mybatis Oracle
Java Mybatis 甲骨文
I have following mybatis statement in xml file
我在 xml 文件中有以下 mybatis 语句
<update id="updateOfferIndex" parameterType="java.util.List">
<foreach collection="list" item="offer" index="index" separator=";" >
UPDATE offer set indx=#{offer.idx} WHERE id=#{offer.eId}
</foreach>
I am getting following error, can any one help ?
我收到以下错误,有人可以帮忙吗?
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
### The error may involve com.dao.linear.upsell.LinearUpsellDao.updateOfferIndex-Inline
### The error occurred while setting parameters
### SQL: UPDATE offer set indx=? WHERE id=? ; UPDATE offer set indx=? WHERE id=?
### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
回答by Maforast
I resolve by insert BEGIN-END statements in this way:
我通过以这种方式插入 BEGIN-END 语句来解决:
BEGIN
<foreach collection="list" item="offer" index="index" separator=";" >
UPDATE offer set indx=#{offer.idx} WHERE id=#{offer.eId}
</foreach>;
END;
I hope this resolves.
我希望这能解决。
回答by s17t.net
Looks like the last semicolon has not been appended:
看起来最后一个分号没有被附加:
### SQL: UPDATE offer set indx=? WHERE id=?;
UPDATE offer set indx=? WHERE id=?;
And this is coherent with the mybatis documentationabout the foreach's separator:
这与有关 foreach 分隔符的 mybatis文档一致:
The element is smart in that it won't accidentally append extra separators.
该元素很聪明,因为它不会意外地附加额外的分隔符。
Try adding a semicolon to the XML mapping:
尝试在 XML 映射中添加分号:
<foreach collection="list" item="offer" index="index" separator=";" >
UPDATE offer set indx=#{offer.idx} WHERE id=#{offer.eId}
</foreach>
;