在Oracle中實現類似自動增加ID的功能

創建序列

create sequence SEQ

minvalue 1

maxvalue 999999999999999999999999999

start with 1

increment by 1

cache 30

order;

創建表

CREATE TABLE table1

(

id NUMBER PRIMARY KEY,

username VARCHAR2(50)

);

創建觸發器

CREATE OR REPLACE TRIGGER table1_tg

BEFORE INSERT ON table1 FOR EACH ROW

BEGIN

SELECT  seq.NEXTVAL INTO :NEW.id FROM DUAL;

END;

你可能感兴趣的:(oracle)