Oracle自增长序列实现
关于自增长序列,昨天我回去尝试了下,可以实现代码项表
–创建表
CREATE TABLE Code_Main
(CodeID NUMBER PRIMARY KEY,
CodeName VARCHAR2(50));
–建序列 www.2cto.com
CREATE SEQUENCE Code_Main_seq
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
CACHE 30
ORDER;
–建触发器
CREATE OR REPLACE TRIGGER Code_Main_tg
BEFORE INSERT ON Code_Main
FOR EACH ROW www.2cto.com
BEGIN
SELECT Code_Main_seq.NEXTVAL INTO :NEW.CodeID FROM DUAL;
END;
INSERT INTO Code_Main (CodeName) VALUES (‘张三’);
作者 平安夜