oracle批量插入(insert)ID自增问题

来源:互联网 发布:linux 查看sftp端口 编辑:程序博客网 时间:2024/05/16 04:57
--1.创建序列
create sequence seq_stu
      increment by 1    -- 每次递增1
      start with 1       -- 从1开始
      nomaxvalue      -- 没有最大值
      minvalue 1       -- 最小值=1
      NOCYCLE;      -- 不循环
      
--2.为序列创建触发事件
create or replace trigger style_insert
  before insert on student 
  for each row
begin
  select seq_stu.nextval into :new.id from dual;
end;
--注(不创建触发事件,以下批量插入序列号不会自增)
--3.批量插入

insert all 

into student (id, name ) values (seq_stu.nextval, '张三') 

into student (id,name) values (seq_stu.nextval, '李四') 
  select 1 from dual;