oracle创建自动增长列、触发器- 徐灿- 博客园

创建自动增长列:

create sequence emp_sequence
increment by 1----每次增加几个
minvalue 1----最小值为1
nomaxvalue----不限制{zd0}值
start with 1----从1开始
cache 10----缓存
order;

 

注解:

currval=返回 sequence的当前值
nextval=增加sequence的值,然后返回 sequence 值
比如:
emp_sequence.currval
emp_sequence.nextval

 

插入测试数据:

insert into sysrole (roleId,roleName,roleDesc) values (emp_sequence.nextval,'管理员','拥有本系统的{zg}权限')

 

创建触发器:

create or replace trigger sysrole_id
before insert on sysrole----(sysrole为表名)
for each row----触发每一行
begin
select emp_sequence.nextval into :new.roleid from dual;
end;

 

插入测试数据:

insert into sysrole (roleName,roleDesc) values ('法律管理员','管理本系统中所有的法律、法规信息及法律、法规会员')

 

{zh1}:

commit---提交所有操作

 

 

posted on 2010-01-15 10:35 阅读(13)   所属分类:

郑重声明:资讯 【oracle创建自动增长列、触发器- 徐灿- 博客园】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——