Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>
Today, we performed the batch insert operation and found that an error MySQL column count doesn’t match value count at row 1 was reported
Later, it was found that the reason is that the number of columns in the SQL statement is inconsistent with the number of values after it, such as insert into table name (field1, field2, field3) values (‘a ‘,’b’), so that there are three columns before and only two values after it, which will cause this error
View mapper writing
1 <insert id="insertBatch" useGeneratedKeys="true" parameterType="java.util.List">
2 INSERT INTO sys_basic_info(
3 <include refid="dbColumns" />
4 ) VALUES
5 <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
6 #{item.groupId},
7 #{item.groupName},
8 #{item.groupCode}
9 </foreach>
10 </insert>
The reason is easy to find, foreach tag attribute open and close configuration error! In this way, braces will wrap the whole
1 <insert id="insertBatch" useGeneratedKeys="true" parameterType="java.util.List">
2 INSERT INTO sys_basic_info(
3 <include refid="dbColumns" />
4 ) VALUES
5 <foreach collection="list" item="item" index="index" separator=",">
6 (
7 #{item.groupId},
8 #{item.groupName},
9 #{item.groupCode}
10 )
11 </foreach>
12 </insert>
Similar Posts:
- [Solved] mybatis Bulk Insert Error: Column count doesn‘t match value count at row 1
- Python pandas merge cannot merge two data frames based on column names (Key Error)?
- How to Solve Error: Cannot read property ‘map’ of undefined
- pymysql.err.OperationalError: (1054, “Unknown column’aa’in’field list’)
- MySQL Error Number 1005 Can’t create table (Errno:150)
- [Solved] Vue error: (Avoid using non-primitive value as key, use stringnumber value instead.)
- MySQL database insert into statement with parameters Error
- Python Pandas: Read_Excel() and to_Excel() function
- Oracle ORA-00936: missing expression [How to Solve]
- When using angularjs procedure, track by $index of NG repeat