1. 程式人生 > >oracle數據庫表實現主鍵自增功能

oracle數據庫表實現主鍵自增功能

back oracle數據 max 序列 val create 主鍵 new row

有關oracle中自序列sequence+觸發器trigger:實現數據表TABDATA_LIVE_CYCLE中的主鍵id的自增

CREATE SEQUENCE TABDATA_LIVE_CYCLE_SEQ
MINVALUE 0
MAXVALUE 9999999999999999999999999999
INCREMENT BY 1
START WITH 1
CACHE 20
NOORDER
NOCYCLE ;

CREATE OR REPLACE TRIGGER TABDATA_LIVE_CYCLE_SEQ_ID_ART
before insert on TABDATA_LIVE_CYCLE
for each row
begin
select TABDATA_LIVE_CYCLE_SEQ.nextval into :new.id from dual;
end ;
/

oracle數據庫表實現主鍵自增功能