Terry's blog

Focus on bigdata and cloud.

博客园 首页 新随笔 联系 订阅 管理

 

1建立数据表

Code

 

2创建自动增长序列

 CREATE SEQUENCE TestIncrease_Sequence
 INCREMENT 
BY 1   -- 每次加几个  
     START WITH 1     -- 从1开始计数  
     NOMAXVALUE       -- 不设置最大值  
     NOCYCLE          -- 一直累加,不循环  
     CACHE 10

 

3创建触发器

CREATE TRIGGER Test_Increase BEFORE
insert ON  Test_Increase FOR EACH ROW
begin
select TestIncrease_Sequence.nextval into:New.userid from dual;

end;

 

4 提交

commit;

5 测试

反复执行如下语句:

insert into Test_Increase(Username) values('test')

 

6 查看插入结果:

userid username

 1       test
 2       test
 3       test
 4       test
 5       test
 6       test
 7       test
 8       test
 9       test

 

posted on 2009-02-13 15:51  王晓成  阅读(11645)  评论(0编辑  收藏  举报