本文简单介绍Oracle自增字段创建的一种方法。
描述:将测试记录表pipe_test的字段id设置为自增字段。
- pipe_test的表结构






- 创建序列
create sequence seq_inc_pipe
start with 1
increment by 1
cache 20;
start with 1
increment by 1
cache 20;
- 创建触发器
create or replace trigger trg_pipe_test_id
before insert on pipe_test
for each row
begin
select seq_inc_pipe.nextval into :new.id from dual;
end trg_pipe_test_id;
before insert on pipe_test
for each row
begin
select seq_inc_pipe.nextval into :new.id from dual;
end trg_pipe_test_id;
- 测试
insert into pipe_test values(1,'test',sysdate);