X.nextval gets the next sequence value of the x sequence, X.currval gets the current sequence value of the x sequence.
Note: In reference to X. You must first refer to xbefore currval . Nextval, otherwise the ORA-08002 is reported: The sequence X.currval has not yet been defined in this session.
Specific applications
1. Create a sequence:
Create sequence Test_seq increment by 1 start with 1 maxvalue minvalue 0 nocycle cache order;
Select Sequence Test_seq.nextval from dual;//once per call nextval, sequence values are incremented one time (increment value custom)
Select sequence Test_seq.currval from dual;
2. Create a table:
CREATE TABLE test (col1 int, col2 int);
3. Insert Record:
INSERT into test values (0, 0);
4, the use of Nextval
INSERT into Test (col1, col2) VALUES (Test_seq.nextval, test_seq.nextval);//Do you guess col1 and col2 values will be the same?
If the test table has two records with a col1 value of 2, then:
Update Test Set col2 = test_seq.nextval where col1 = 2;//Do you guess the col2 value will be the same after the update?
The application of Nextval,currval in the database.