< update id="batchUpdate">
UPDATE eplus_project_standard
SET device_type_id = contents.device_type_id,
type = contents.type,
project_id = contents.project_id,
summary = contents.summary,
detail = contents.detail,
period_type = contents.period_type,
period_value = contents.period_value,
index = contents.index
FROM (
VALUES
<foreach collection ="standards" item="stand" index="index"
open="" close= "" separator= ",">
(#{stand.deviceType.id},
<trim suffix="::jsonb"> #{stand.standard}</trim >
#{stand.type},
#{stand.projectId},
#{stand.id},
#{stand.summary},
#{stand.detail},
#{stand.periodType},
#{stand.periodValue},
#{stand.index})
</foreach>
contents(device_type_id, standard,type,project_id,id, summary,detail, period_type, period_value, index)
WHERE
contents.id
= eplus_project_standard.id;
</update >
但是有些时候,列的类型为特殊类型。列的value为null,则sql判断不出value应该是什么类型,会抛出错误。我们在sql中指定类型就可以了。
demo:
<update id= "updateBatch">
update ps_fair_places
fair_id=place.fairId,
organization_id=place.orgId,
status=place.status,
current_interviewer=place.currentInterviewerId,
current_participant=place.currentParticipantId,
jobs =place.jobs,
channel=place.channel:: jsonb,
allow=place.allow,
interview_id=place.currentInterviewId,
start_time=place.startTime:: timestamp without time zone,
end_time=place.endTime:: timestamp without time zone
from (
values
<foreach collection ="fairPlaces" item="p" open= "" close =""
separator= ",">
<trim prefix ="(" suffix=")">
#{p.id},
<choose >
<when test ="p.fair != null">#{p.fair.id},</ when>
<otherwise >null, </otherwise>
</choose>
<choose >
<when test ="p.org != null">#{p.org.id},</ when>
<otherwise >null, </otherwise>
</choose>
#{p.status},
<choose >
<when test ="p.currentInterviewer != null">
#{p.currentInterviewer.id},
</when>
<otherwise > null, </otherwise>
</choose>
<choose >
<when test ="p.currentParticipant != null">
#{p.currentParticipant.id},
</when>
<otherwise > null, </otherwise>
</choose>
<choose >
<when test ="p.jobs != null">
<trim prefix ="ARRAY[" suffix= "]">
<foreach collection="p.jobs" item ="job" separator=","> #{job.id}
</foreach>
</trim>
</when>
<otherwise >
null,
</otherwise>
</choose>
<choose >
<when test ="p.channel != null">
#{p.channel},
</when>
<otherwise > null, </otherwise>
</choose>
#{p.allow},
#{p.currentInterviewId},
#{p.startTime},
#{p.endTime}
</trim>
</foreach>
) as place(
fairId,
orgId,
status,
currentInterviewerId,
currentParticipantId,
jobs,
channel,
allow,
currentInterviewId,
startTime,
endTime
where place.id = ps_fair_places.id
</update >
转载于:https://my.oschina.net/u/347227/blog/845724
原文链接:https://my.oschina.net/u/347227/blog/845724
1、MySQL
MySQL声称自己是最流行的开源数据库。LAMP中的M指的就是MySQL。构建在LAMP上的应用都会使用MySQL,如WordPress、Drupal等大多数php开源程序。MySQL最初是由MySQL AB开发的,然后在2008年以10亿美金的价格卖给了Sun公司,Sun公司又在2010年被Oracle收购。Oracle支持MySQL的多个版本:Standard、Enterprise、Classic、Cluster、Embedded与Community。其中有一些是免费下
-1的数据才能进行status更新.其他的将使用默认值更新,而不会保持原数据不变.如果要保持原数据不变呢?即满足条件的更新,不满足条件的保持原数据不变,简单的来做就是再加一个,因为mybatis中没有if…这条sql的意思是,如果id为1,则name的值为name1,title的值为New Title1;MySQL没有提供直接的方法来实现批量更新,但可以使用case when语法来实现这个功能。经测试 100条数据的时候第一种方式的效率比第二种差不多高1倍。3 更新多条记录为多个字段为不同的值。...
Mybatis 大数据量的批量update解决方案自定义update table set (...) from values (xxx,xxx,...)网上其他处理方法的限制
自定义update table set (…) from values (xxx,xxx,…)
Mapper.xml
<update id="updateBatch" parameterType="java.uti...
I'm writing a Django-ORM enchancement that attempts to cache models and postpone model saving until the end of the transaction. It's all almost done, however I came across an unexpected difficulty in ...
Mybatis中的CRUD操作(增删改查)中,简单的SQL操作比较直观,如查找操作:
<select id="findBySrcId" resultMap="entityRelationResultMap">
SELECT * FROM ENTITY_RELATION WHERE SRC_ID=#{srcId}
</select>
其中id对应同名java文件中的方法,...