<insert id="insertTopnCallerAddressAndNum" parameterType="list">
insert into table_name(column1,column2,column3,column4)
<foreach collection="list" item="toplist" separator="UNION ALL">
(select #{toplist.COLUMN1,jdbcType=VARCHAR},#{toplist.COLUMN2,jdbcType=NUMERIC},0,#{toplist.COLUMN4,jdbcType=VARCHAR} from dual)
</foreach>
</insert>
注意:myBatis的批量插入和mysql不同。
语言 |
方法 |
5620 |
aAdHQGntrO |
277a1 |
现在做什么生意赚钱 |
1527 |
2010/03/10 15:40:36 |
注解版mybatis_oracle批量插入:
@Insert({
"<script>",
"insert into phoneinfo (",
"id," ,
"phone," ,
"phone_type, " ,
"insert_time," ,
"insert_user ) (" ,
"<foreach collection='phoneInfos' item='phone' index='index' separator='union all'>",
" (select #{phone.id,jdbcType=VARCHAR}, " ,
" #{phone.phone,jdbcType=VARCHAR}, " ,
" #{phone.phone_type,jdbcType=VARCHAR}, " ,
" to_date(#{phone.insert_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'), " ,
" #{phone.insert_user,jdbcType=VARCHAR} from dual)" ,
"</foreach> )",
"</script>"
})
int betchInsertPhone(@Param("phoneInfos")List<PhoneInfo> phoneInfos);
注意:在批量插入的时候如果不限制批量插入的条数,则会出现下面问题:
2019-11-21 15:00:12.365 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError: null
at com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser.primaryRest(OracleExprParser.java:668)
at com.alibaba.druid.sql.parser.SQLExprParser.primary(SQLExprParser.java:796)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser.primary(OracleExprParser.java:462)
at com.alibaba.druid.sql.parser.SQLExprParser.expr(SQLExprParser.java:86)
at com.alibaba.druid.sql.parser.SQLExprParser.exprList(SQLExprParser.java:1279)
|