Preface:
In the project, we sometimes need to make a field from growth, if every time after reading out from the database, plus a fixed value, one is too much trouble, and second, there is a time difference may result in inaccurate data. SEQUENCE can be defined in the database
text:
1. Create
The CREATE the SEQUENCE seqTest the INCREMENT BY 1 - each addition Several the START the WITH 1 - start counting from 1 NOMAXVALUE - does not set the maximum value of the NOCYCLE - has been accumulated, the cycle is not the CACHE 10 ; - setting buffer cache sequences, so to obtain faster. However, if the system is down or otherwise will lead to a sequence of discrete, it may be provided to NOCACHE
2, using
seqtest.currval: Returns the current value. To use after the first nextval initialization, otherwise it will error
Value increase, and increase the return: seqtest.nextval
INSERT INTO table_name (ID, name) values (seqTest.Nextval, ' Sequence insertion test ' );
3, change the parameters
We have ALTER ANY SEQUENCE privileges to change sequence; all parameters except the start can be modified; if you want to change the start value, you must drop sequence and then re-create (delete and re-create).
alter sequence seqTest maxvalue 9999999;
4, delete
DROP SEQUENCE seqTest;
Reference blog:
ORACLE SEQUENCE usage - wretched Dian Yu Wei - blog Park
https://www.cnblogs.com/hyzhou/archive/2012/04/12/2444158.html