oracle 序列和触发器实例

--建立自增序列
create sequence seqid
NOMAXvalue
start with 1
increment by 1
nocache
order;
--建立触发器
create or replace trigger tri_test_id
  before insert on mytable   --mytable为要插入自增序列的表
  for each row
declare
  nextid number;
begin
  IF :new.Id IS NULL or :new.Id=0 THEN   --id是要插入自增序列的列名
    select seqid.nextval 
    into nextid
    from sys.dual;
    :new.Id:=nextid;
  end if;
end tri_test_id;

 

posted @ 2013-03-12 16:19  panlovestan  阅读(133)  评论(0编辑  收藏  举报