SqlServer 和MySql都有自增加的功能,而Oracle必须接结合sequence序列(通常用于主键列),并使用触发器才可以实现自动增加,具体步骤以下:html
1、 建表数据库
create table list(id number,name varchar2(50));spa
2、 建立序列orm
1. create sequence list_seqhtm
2. minvalue 1blog
3. maxvalue 99999999999999rem
4. start with 1get
5. increment by 1it
6. cache 20table
7. order;
http://www.finereport.com/forumimages/o-order.jpg
3、 建立触发器
1. Create or replace trigger list_tg
2. Before insert on list
3. For each row
4. Begin
5. Select list_seq.nextval into :new.id from dual;
6. End;
http://www.finereport.com/forumimages/o-trigger1.jpg
http://www.finereport.com/forumimages/o-trigger2.jpg
http://www.finereport.com/forumimages/o-trigger3.jpg
4、 插入数据
Insert into list values(’’,’aaa’);
Insert into list values(’’,’bbb’);
Select * from list ;
结果为:
ID name
1 aaa
2 bbb
在Oracle 10g 的em 操做界面按照上图配置便可实现自增加序列,数据库端设置完成;
在插入数据时自增加字段可由空值’ ’或null代替,若是insert 语句中列出了所插入的字段,如insert into list(name) values(’aaa’),则增加字段不用写 ;如模板所示为一简单的表单,ID字段绑定数据库中的自增加列,BS填报时,id字段不输入若输入任意数字时,数据库中都按照自增加的规律进行赋值,以下图所示:
http://www.finereport.com/forumimages/o-assign1.jpg
http://www.finereport.com/forumimages/o-assign2.jpg