First, create a table:
CREATE TABLE test ( ID number (+) NOT null primary key, name VARCHAR2 (32));
Then, customize a sequence (sequence)
CREATE SEQUENCE test_sequenceincrement by 1--each time you add a few start with 1--counting from 1 nomaxvalue--not setting the maximum nocycle--always accumulating, not looping nocache- -Do not build buffers
You also need to create a trigger (trigger)
Create TRIGGER Test_trigger before INSERT on test for each ROW time (new.id is null)--Starts the trigger when the ID is NULL to generate ID number be Gin Select Test_sequence.nextval into:new.id from Sys.dual;end;
inserting test Data
INSERT INTO Test (' Zhangsan '): INSERT into Test (ID, name) VALUES (101, ' Lisi ');
Results:
PS: ":" in Into:new.id from sys.dual when creating trigger is close to new rather than into:new.id from sys.dual
Itmyhome
Oracle self-Increment ID implementation