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;
--注(不創建觸發事件,以下批量插入序列號不會自增)
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>

浙公網安備 33010602011771號