oracle创建自动增长列和触发器
来源:优易学  2010-1-19 17:12:56   【优易学:中国教育考试门户网】   资料下载   IT书店

  创建自动增长列:

  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---提交所有操作

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训