Originally published on Netease blog 17:30:17
MySQL was previously viewed at school and used for a period of time. It is relatively simple to create an auto-incrementing field in MySQL.
For example, in the table creation statement, Id int key auto_increment. At last, fill in the corresponding fields during insert.
However, in Oracle, we haven't seen people around us directly create an auto-incrementing field. I searched the internet and said it was not supported in many documents. to implement auto-increment fields, you can only implement them in other ways. for example, sequence.
Create sequence seq_test minvalue 1 maxvalue 99999 start with 1 increment by 1 cycle nocache;
Cycle indicates that the cycle starts from the minimum value after the maximum value is reached. nocache does not cache the sequence value.
In this way, you can enter sequence. nextval in the corresponding position when inserting a record. You can also use sequence. currval to view the current sequence value.
The difference is that if sequence has not been called. nextval, sequnce is called. currval reports an error. call sequence. nextval increases the Sequence Value and returns the current value. sequence. currval does not change the sequence value.