oracle创建自动增长列、触发器

创建自动增长列:

create sequence emp_sequence
increment by 1----每次增加几个
minvalue 1----最小值为1
nomaxvalue----不限制最大值
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,'管理员','拥有本系统的最高权限')

 

创建触发器:

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 ('法律管理员','管理本系统中所有的法律、法规信息及法律、法规会员')

 

最后:

commit---提交所有操作

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值