--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;
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐