首页 > 代码库 > 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 --批量插入
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。