In projects, batch operation statements are often needed to operate data. When using batch statements, you need to pay attention to the conditional restrictions of the MySQL database. The main restriction here is the size of the data. Here is a brief summary of the basic operations of batch insertion, batch search, and batch update. 1. Batch insert statements. The following statements have been used to insert more than 10,000 data in a test environment. The specific number depends on the table structure and field content. <insert id="addTextPushList" paramerterType="java.util.List"> INSERT INTO SYS_TEXT_PUSH( PUSH_ID, USER_UM_ACCOUNT, USER_NAME, SECTION, USER_MOBILE, PUSH_STATUS, PROMOTE_ID, CREATED_BY, CREATION_DATE, ENABLED_FLAG )values <foreach collection=”list” item = “item” separator=”,”> ( #{item.pushId}, #{item,userUmAccount}, #{item.userName}, #{item.section}, #{item.userMobile}, #{item.pushStatus}, #{item.promoteId}, #{item.createdBy}, #{item.creationDate}, #{item.enabledFlag} ) </foreach> </insert> 2. Batch select query statement <select id = "getTextPromoteByIds" parameterType = "java.util.list" resultMap = "textPromoteMap"> SELECT * FROM SYS_TEXT_PROMOTE WHERE TEXT_PUSH_FLAG = 1 AND PROMOTE_ID IN <foreach collection=”list” item = “item” open=”(” separator=”,” close =”)”> #{item} </foreach> </select> 3. Batch update statements. The first case is when the values to be updated are the same: <update id="updatePushStatus" parameterType="java.util.List"> update SYS_TEXT_PUSH SET PUSH_STATUS = 1, LAST_UPDATE_DATE = NOW() WHERE PUSH_ID IN <foreach collection=”list” item = “item” open=”(” separator=”,” close =”)”> #{item} </foreach> </update> The second case is when the values to be updated are different: <update id="updatePushStatus" parameterType="java.util.List"> <foreach collection="list" item = "item" index = "index"> update SYS_TEXT_PUSH SET PUSH_STATUS = #{item.pushStatus}, LAST_UPDATE_DATE = NOW() WHERE PUSH_ID = #{item.pushId} </foreach> </update> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed tutorial on uploading and configuring jdk and tomcat on linux
>>: Vue uses Baidu Maps to realize city positioning
There are three pages A, B, and C. Page A contains...
Table of contents 1. Teleport usage 2. Complete t...
The previous article has installed the docker ser...
concept MMM (Master-Master replication manager fo...
We often need to summarize data without actually ...
Use JOIN instead of sub-queries MySQL supports SQ...
I have written such an article before, but I used...
MySQL DDL statements What is DDL, DML. DDL is dat...
First, you need to download and install Navicat f...
This article records the installation graphic tut...
Linux installation JDK1.8 steps 1. Check whether ...
How to use css variables in JS Use the :export ke...
This article shares the specific code of JavaScri...
Table of contents 1. Introduction to jQuery 2. jQ...
Today, when I was using Nginx, a 500 error occurr...