建表
CREATE TABLE table1
(id NUMBER PRIMARY KEY,
username VARCHAR2(50));
--建序列
CREATE SEQUENCE table1_seq
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
CACHE 30
ORDER;
--建触発器
CREATE OR REPLACE TRIGGER table1_tg
BEFORE INSERT ON table1
FOR EACH ROW
BEGIN
SELECT table1_seq.NEXTVAL INTO :NEW.id FROM DUAL;
END;
--執行
INSERT INTO table1 (username) VALUES ('張三');
CREATE TABLE table1
(id NUMBER PRIMARY KEY,
username VARCHAR2(50));
--建序列
CREATE SEQUENCE table1_seq
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
CACHE 30
ORDER;
--建触発器
CREATE OR REPLACE TRIGGER table1_tg
BEFORE INSERT ON table1
FOR EACH ROW
BEGIN
SELECT table1_seq.NEXTVAL INTO :NEW.id FROM DUAL;
END;
--執行
INSERT INTO table1 (username) VALUES ('張三');