Home > Database > Mysql Tutorial > 实现Oracle数据库的逐渐自增

实现Oracle数据库的逐渐自增

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:55:11
Original
1170 people have browsed it

1、 第一次NEXTVAL返回的是初始值;随后的NEXTVAL会自动增加你定义的INCREMENT BY值,然后返回增加后的值。CURRVAL 总是返回当前

将表t_uaer的字段ID设置为自增:(用序列sequence的方法来实现)

----创建表
Create table t_user(
Id number(6),userid varchar2(20),loginpassword varchar2(20),isdisable number(6)
);

----创建序列
create sequence user_seq
increment by 1
start with 1
nomaxvalue
nominvalue
nocache

----创建触发器
create or replace trigger tr_user
before insert on t_user
for each row
begin
select user_seq.nextval into :new.id from dual;
end;

----测试
insert into t_user(userid,loginpassword, isdisable)
values('ffll','liudddyujj', 0);
insert into t_user(userid,loginpassword, isdisable)
values('dddd','zhang', 0)
select * from t_user;
就可以看出结果。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template