oracle设置自动增长列

1.建表

create table VACATION
(
ID number(8) primary key,
TITLE VARCHAR2(200),
MATTER VARCHAR2(200),
APPLYER VARCHAR2(20),
STARTTIME VARCHAR2(20),
ENDTIME VARCHAR2(20)
)


2.建序列

create sequence vacation_seq minvalue 1 maxvalue 999999999999999999 start with 1 increment by 1 cache 20;

3.建触发器

CREATE OR REPLACE TRIGGER "vacation_trig"
BEFORE INSERT ON VACATION
REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
DECLARE
BEGIN
SELECT vacation_seq.NEXTVAL INTO :NEW.id FROM DUAL;
END vacation_trig;

搞定!

你可能感兴趣的:(oracle)