Mybatis+Oracle --批量插入
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis+Oracle --批量插入相关的知识,希望对你有一定的参考价值。
Oracle自增长ID:
mybatis语句
参考博客:点评 ibatis+oracle 批量插入的三种方法. 参考第三种
Oracle自增长ID,如下:
序列:
CREATE SEQUENCE "ENERGY"."ROLE_OBJECT_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 150 NOCACHE NOORDER NOCYCLE ;
触发器:
CREATE OR REPLACE TRIGGER TRIGGER_ROLE_OBJECT BEFORE INSERT ON SYS_RIGHT_ROLE_OBJECT FOR EACH ROW BEGIN SELECT ROLE_OBJECT_SEQ.nextval into :new.ROLE_OBJECT_ID from dual; END;
Mybatis :
<insert id="insertSelectiveByList" parameterType="java.util.List"> insert into SYS_RIGHT_ROLE_OBJECT (ROLE_CODE, OBJECT_CODE, POLICY_ID, PERMISSION) <foreach collection="list" item="item" index="index" open="(" close=")" separator="UNION ALL"> SELECT #{item.roleCode} AS ROLE_CODE, #{item.objectCode} AS OBJECT_CODE, #{item.policyId} AS POLICY_ID, #{item.permission} AS PERMISSION FROM dual </foreach> </insert>
以上是关于Mybatis+Oracle --批量插入的主要内容,如果未能解决你的问题,请参考以下文章