oracle批量插入自增问题【转】

--1.创建序列
create sequence seq_paper_choice
      increment by 1    -- 每次递增1
      start with 1       -- 从1开始
      nomaxvalue      -- 没有最大值
      minvalue 1       -- 最小值=1
      NOCYCLE;      -- 不循环
      
--2.为序列创建触发事件
create or replace trigger style_insert
  before insert on
paper_choice (表名)
  for each row
begin
  select seq_paper_choice.nextval into :new.id from dual;
end;
--注(不创建触发事件,以下批量插入序列号不会自增)
 
--oracle 批量插入mybatis写法
<!--批量新增-->
<insert id="insertRandChoice" parameterType="java.util.List">
INSERT ALL
<foreach collection="list" item="item" index="index">
INTO paper_choice (id,content, aoption,boption,coption,doption, answer ,examid)
VALUES(seq_paper_choice.nextval,
#{item.content,jdbcType=VARCHAR},
#{item.aoption,jdbcType=VARCHAR},
#{item.boption,jdbcType=VARCHAR},
#{item.coption,jdbcType=VARCHAR},
#{item.doption,jdbcType=VARCHAR},
#{item.answer,jdbcType=VARCHAR},
#{item.examid,jdbcType=DECIMAL})
</foreach>
SELECT 1 FROM DUAL
</insert>
原文地址:https://www.cnblogs.com/hmhhz/p/13536443.html