本文介绍: oracle数据库批量更新mysql中的有些不一样,需要进行如下修改。上边这个执行时候报错ORA-00933:SQL命令正确结束。对上边的代码进行改变。

项目场景

最近在开发项目过程中遇见了这个问题:Oracle批量更新时候报错 ORA-00933:SQL命令未正确结束


问题描述

mybatis批量更新报错ORA-00933:SQL命令未正确结束

<foreach item="item" index="index" collection="list" separator=";">
	update A
	set ID=#{item.id}
	where NAME=#{item.name}
</foreach&gt;

上边这个执行时候报错ORA-00933:SQL命令未正确结束


原因分析

oracle数据库批量更新和mysql中的有些不一样,需要进行如下修改


解决方案

对上边的代码进行改变

  1. separator=“;” 这个里边一定要加分号,而不是逗号
  2. beginend必须要成对出现 open=“beginend=“;end;” 也就是为了补全语法
<foreach item="item" index="index" collection="list"  open="begin" end=";end;"  separator=";"&gt;
	update A
	set ID=#{item.id}
	where NAME=#{item.name}
</foreach&gt;

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注