ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle 字段递增 表插入数据,id自动增1

oracle 字段递增 表插入数据,id自动增1

原创 Linux操作系统 作者:kekehanmu23 时间:2009-03-05 11:09:19 0 删除 编辑
oracle 字段递增 表插入数据,id自动增1
1、创建表

create table test(id int,
name varchar(32))

2、创建序列
create sequence TID_seq
minvalue 1
maxvalue 999999
start with 1
increment by 1
cache 20
;

3、创建触发器

create or replace trigger test_tri
before insert on test for each row
begin
select to_char(TID_seq.nextval) into :new.id from dual;
end test_tri;

4、插入数据

insert into test(name) values ('a')

insert into test(name) values ('b')

select * from test


应该 出现

1,a

2, b

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12297816/viewspace-561463/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 做ERP好比彈钢琴
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2008-06-05

  • 博文量
    2
  • 访问量
    2995