创建自动增长列:
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) 所属分类: