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>