码迷,mamicode.com
首页 > 数据库 > 详细

oracle id 自动增长

时间:2015-07-08 18:04:57      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

--创建表

create table abc(
id number(4) not null primary key,
username varchar2(20) not null,
pwd varchar2(20) not null
);

--创建序列

create sequence abc_sequence
  increment by 1
  start with 1
  maxvalue 9999
  cycle nocache;

--创建触发器

create or replace trigger abc_trigger
       before insert on abc for each row
       begin
          select abc_sequence.nextval into:new.id from dual;
      end;

 

 

insert into abc(username, pwd) values(‘Tony‘, ‘a‘);

insert into abc(username, pwd) values(‘Tony1‘, ‘a‘);
select * from abc;

oracle id 自动增长

标签:

原文地址:http://www.cnblogs.com/dl30373/p/4630630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!