首页 > 数据库技术 > 详细

oracle id 自动增长

时间:2015-07-08 18:02:54      阅读:336      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!