注意:与MySQL不同!
方式一
insert all into table(...) values(...) into table(...) values(...) select * from dual;
<insert id="addList" parameterType="java.util.List" useGeneratedKeys="false">
INSERT ALL
<foreach item="item" index="index" collection="list">
INTO T_APPLAUD
(
ID,
USER_ID,
BUSINESS_TYPE,
PRODUCT_ID,
CREATE_TIME
) VALUES
(
#{item.id, jdbcType=NUMERIC},
#{item.userId, jdbcType=VARCHAR},
#{item.businessType, jdbcType=VARCHAR},
#{item.productId, jdbcType=VARCHAR},
#{item.createdTime, jdbcType=NUMERIC}
)
</foreach>
SELECT 1 FROM DUAL
</insert>
举例:
INSERT ALL
INTO tableName (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO tableName (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO tableName (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT count(*) FROM dual;
【注】:查询语句“SELECT count(*) FROM dual;”不能少,需要一条查询语句,查询结果不重要。
方式二
insert into table(...) (select ... from dual) union all (select ... from dual)
<insert id="addList" parameterType="java.util.List" useGeneratedKeys="false">
INSERT INTO T_APPLAUD
(
ID,
USER_ID,
BUSINESS_TYPE,
PRODUCT_ID,
CREATE_TIME
)
<foreach item="item" index="index" collection="list" separator="union all">
(
SELECT
#{item.id},
#{item.userId},
#{item.businessType},
#{item.productId},
#{item.createdTime}
FROM DUAL
)
</foreach>
</insert>