首页 > 代码库 > Mybatis+Oracle --批量插入

Mybatis+Oracle --批量插入

Oracle自增长ID:

参考博客:Oracle数据库创建表ID字段的自动递增

mybatis语句

参考博客:点评 ibatis+oracle 批量插入的三种方法. 参考第三种

参考博客:mybatis中批量插入的两种方式(高效插入)

 

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 --批量插入