Step: 1. Create a sequence
2. Create a trigger.
Syntax parsing:
Create sequence Tb_code_sequence
MinValue 1
MaxValue 999999999999999999999999999
Start with 11
Increment by 1
Cache 10;
CREATE OR REPLACE TRIGGER tb_code_increase before insert on Tb_code
For each ROW
Begin
Select Tb_code_sequence.nextval Into:New.ID from dual;
End
Create sequence tb_code_sequence---Creates a sequence named Tb_code_sequence.
MinValue 1---Minimum value is 1
MaxValue---Maximum value, you can set any positive integer value on MaxValue. When no value is set, the default is 999999999999999999999999999
Start with one---starting with the 11th record, starting from 1 when no records are recorded in the table
Increment by 1---increment value is 1, increments by 1 each time
Cache---Cache defines the size of the memory block that holds the sequence, which defaults to 20.
Create OR REPLACE TRIGGER tb_code_increase---Creating a trigger named Tb_code_increase
Before insert on Tb_code---defines when the trigger is fired, defined here to fire the trigger before inserting the Tb_code table
For each row---loop each row
Begin
Select Tb_code_sequence.nextval Into:New.ID from dual; ---The value returned by Nextval in the query sequence and returns it to the sequence.
End
Modify:
Some parts of the sequence can also be modified in use, but the SATRT with option cannot be modified.
Changes to the sequence affect only the resulting ordinal number, and the number that has been generated is unchanged.
Note that it is best to do these operations natively.
Oracle Resume Auto-increment sequence (RPM)