--建序列
create sequence seq_id
increment by 1 --每次加1
start with 1 --从1开始
nomaxvalue --不设最大值
nocycle --一直累加,不循环
nocache --不建缓冲区
--minvalue 1 --最小值
/* 注:一般在项目中会用缓冲区,提高效率,(格式:cache 20)
缺点,如果ORACLE死机或者其它意外情况,会出到序列不连续的情况
如果设置了最大值,一定要设置累加循环(maxvalue 10000,cycle)*/
--自动增长触发器
drop trigger tri_seq_id
create trigger tri_seq_id before
insert on test_zhi for each row when(new.test_zhi_id is null)
begin
select seq_id.nexval into :new.test_zhi_id from dual;
end;
--插入数据
insert into test_zhi values(seq_id.nextval,'姓名2abcd','地址2abcd');
create sequence seq_id
increment by 1 --每次加1
start with 1 --从1开始
nomaxvalue --不设最大值
nocycle --一直累加,不循环
nocache --不建缓冲区
--minvalue 1 --最小值
/* 注:一般在项目中会用缓冲区,提高效率,(格式:cache 20)
缺点,如果ORACLE死机或者其它意外情况,会出到序列不连续的情况
如果设置了最大值,一定要设置累加循环(maxvalue 10000,cycle)*/
--自动增长触发器
drop trigger tri_seq_id
create trigger tri_seq_id before
insert on test_zhi for each row when(new.test_zhi_id is null)
begin
select seq_id.nexval into :new.test_zhi_id from dual;
end;
--插入数据
insert into test_zhi values(seq_id.nextval,'姓名2abcd','地址2abcd');