致虚极,守静笃!

创建Oracle序列sequence

create sequence SEQ_ID
minvalue 1
maxvalue 99999999
start with 1
increment by 1
nocache
order;

建解发器代码为:

create or replace trigger tri_test_id
  before insert on test   --S_Depart 是表名
  for each row
declare
  nextid number;
begin
  IF :new.id IS NULL or :new.id=0 THEN --DepartId是列名
    select SEQ_ID.nextval --SEQ_ID正是刚才创建的
    into nextid
    from sys.dual;
    :new.id:=nextid;
  end if;
end tri_test_id;

  

posted @ 2019-07-26 11:46  Baron-Li  阅读(134)  评论(0编辑  收藏  举报

致虚极,守静笃!