oracle 12c之前必须用sequence :
create table test_tab
(
id number primary key
);
create sequence test_seq start with 1 increment by 1 nocycle;
create or replace trigger test_trg
before insert on test_tab
for each row
begin
select test_seq.nextval into :new.id
from dual;
end;
/
12c之后可以直接定义 字段的默认值为一个自增序列
create sequence test_seq start with 1 increment by 1 nocycle;
create table test_tab
(
id number default test_seq.nextval primary key
);
使用触发器
insert into test(name) values(‘sss’)