1. 程式人生 > >Mybatis+Oracle --批量插入

Mybatis+Oracle --批量插入

tar 方式 sys ctc .net util dual 博客 --

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