最近由于业务需要,需要自增的序列来满足当数据插入时自动填上数字
测试如下:
create table test (id integer,status integer default 2,nam varchar2(10),info varchar2(50));
创建序列:
create sequence test_seq start with 1 increment by 1;
创建触发器:
create or replace trigger test_trigger
before insert on test
for each row
when(new.id is null)
begin
select t_user_seq.nextval into:NEW.ID from dual;
end;
当insert into test (name,info) values ('xxx','dshjdhakjhd');commit;
select * from test;即可查看到自动产生的序列。