create sequence SEQ_ID
minvalue 1
maxvalue 99999999
start with 1
increment by 1
nocache
order;
建解发器代码为:
1
2
3
4
5
6
7
8
9
10
11
12
13
create or replace trigger tri_test_id
before insert on S_Depart --S_Depart 是表名
for each row
declare
nextid number;
begin
IF :new.DepartId IS NULLor :new.DepartId=0 THEN --DepartId是列名
select SEQ_ID.nextval --SEQ_ID正是刚才创建的
into nextid
from sys.dual;
:new.DepartId:=nextid;
end if;
end tri_test_id;