1. Create a sequence
--Create sequence
Create sequence Innerid
MinValue 1
MaxValue 99999999999999
Start with 1
Increment by 1
Cache 20
Order
2.--innerid.currval refers to the current sequence
--innerid.nextval refers to the next sequence
Insert into admin values (innerid.nextval, ' a ');
Insert into admin values (innerid.nextval, ' B ');
Insert into admin values (innerid.nextval, ' C ');
Insert into admin values (innerid.nextval, ' d ');
CREATE TABLE Admin
(ID varchar2 (), name VARCHAR2 (10));
--constant insertion of the next value of the sequence.
3. Create a trigger (note: The default value for ID cannot be set here is Innerid.nextval)
CREATE OR REPLACE TRIGGER ADMIN_TG
Trigger for--admin ID
Before INSERT on admin for each ROW
BEGIN
SELECT Innerid. Nextval INTO:NEW.id from DUAL;
END;
The test statements are as follows:
Insert into admin (username) VALUES (' Zdz ');
If you successfully insert the data, and then look at the data, you can see that the ID has grown automatically and this problem is resolved!
The implementation process of Oracle database Auto-Growth column