orecle 自增长id

Posted hu-kang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了orecle 自增长id相关的知识,希望对你有一定的参考价值。

--1.创建表
create table Student(
ID integer not null primary key,
Name varchar2(40) not null,
Sex integer,
Address varchar2(100)
)

--2.创建序列
 CREATE SEQUENCE  名称  

MINVALUE 1

MAXVALUE 999999999

INCREMENT BY 1

START WITH 1

CACHE 20 NOORDER  NOCYCLE ;

--3.创建触发器
create OR REPLACE TRIGGER Trigger_StuID
BEFORE insert
ON Student
FOR EACH ROW
BEGIN
if inserting then
if :NEW."ID" is null then
select SEQ_StuID.nextval into :NEW."ID" from dual;
end if;
end if;
END;

以上是关于orecle 自增长id的主要内容,如果未能解决你的问题,请参考以下文章