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;

浙公网安备 33010602011771号