mysql迁移dm数据库迁移, insert ignore into语句不能使用, 批量插入语句和Oracle一致
DM Mybatis中xml批量执行
<foreach collection="list" item="device" separator=";">
MERGE INTO eq_group_device t1 USING
(SELECT #{device.id} AS id,#{device.groupId} AS groupId,#{device.deviceId} AS deviceId FROM dual) t2
ON
(t1.group_id = t2.groupId AND t1.device_id = t2.deviceId)
WHEN MATCHED THEN
UPDATE SET t1.id = t2.id
WHEN NOT MATCHED THEN
INSERT (id,group_id,device_id) VALUES (t2.id,t2.groupId,t2.deviceId)
</foreach>
MYSQL Mybatis中xml批量执行 不通过主键效验重复字段
INSERT INTO tb_alarm_whitelist
(id, dz_code, device_name, device_code, label)
SELECT * FROM (
<foreach collection="devices" item="dev" separator="UNION ALL ">
SELECT #{dev.id} AS id,
#{dev.dzCode} AS dzCode,
#{dev.deviceCode} AS deviceCode,
#{dev.deviceName} AS deviceName,
#{dev.label} AS label FROM DUAL
</foreach>
) a WHERE NOT EXISTS(
SELECT dz_code FROM tb_alarm_whitelist b WHERE a.dzCode = b.dz_code
)