众所周知,在SQL Server中设置自增长列很简单,但是在ORACLE中则不然,现在介绍一下ORACLE中自增长列如何实现:
1.创建序列。
举例如下:
create sequence seq_person
increment by 1
start with 1
nomaxvalue --不设最大值
nocycle -- 一直累加,不循环
cache 10; --建立缓存区
其中seq_person是序列的名称,minvalue是你想要设置的最小值,maxvalue是最大值,start with 1 表示从1开始,increment by 1表示每次增加1。
使用方法:insert into person (id,name) values(seq_person.nextval,'wwww');2.创建触发器。create or replace trigger trig_auto_incre before insert on table for each row as begin select seq_name.nextval into :new.id from dual; end;需要注意的是:创建触发器时候表名,序列名必须用大写。按照上述步骤完成后就可以使用了,假如表FileInfo_GW有两个字段id,title.id为自动增长列,插入语句如下:insert into FileInfo_GW(title) values ('关于XXX的通知');这样就可以实现和Sql Server自增长列相同的效果了。