Chinaunix首页 | 论坛 | 博客
  • 博客访问: 172942
  • 博文数量: 33
  • 博客积分: 761
  • 博客等级: 上士
  • 技术积分: 364
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-15 23:56
个人简介

梦想主义者

文章分类

全部博文(33)

文章存档

2012年(33)

分类: Oracle

2012-12-18 22:47:14

在MySQL中,可以使用auto_increment实现id的自动增加。在Oracle中并没有这个属性。但是可以使用其它的方法来实现这个功能。主要就是利用序列和触发器两张方法。

第一种:序列

首先创建一个序列:

create sequence emp_seq increment by 1 start with 1 nomaxvalue nocycle cache 10
引用序列 
insert into emp values(emp_seq.nextval,'zhaokeke') 第二种:触发器

create or replace trigger EMP_TRIG
before insert on EMP referencing old as old new as new for each row
declare next_id number;
begin select EMP_SEQ.nextval into next_id from dual; :new.info_id:=next_id;
end;


阅读(1796) | 评论(0) | 转发(0) |
0

上一篇:jQuery语法

下一篇:我的2012

给主人留下些什么吧!~~