Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / Sequences
 

When you select currval , nextval remains unchanged; nextval only changes when you select nextval to get the next value

SQL> SQL> CREATE SEQUENCE test_seq; Sequence created. SQL> SQL> SELECT test_seq.nextval FROM dual;    NEXTVAL ----------          1 SQL> SQL> SELECT test_seq.nextval, test_seq.currval FROM dual;    NEXTVAL    CURRVAL ---------- ----------          2          2 SQL> SQL> SELECT test_seq.nextval, test_seq.currval FROM dual;    NEXTVAL    CURRVAL ---------- ----------          3          3 SQL> SELECT test_seq.nextval, test_seq.currval FROM dual;    NEXTVAL    CURRVAL ---------- ----------          4          4 SQL> SQL> SELECT test_seq.nextval, test_seq.currval FROM dual;    NEXTVAL    CURRVAL ---------- ----------          5          5 SQL> SQL> SELECT test_seq.nextval, test_seq.currval FROM dual;    NEXTVAL    CURRVAL ---------- ----------          6          6 SQL> SQL> SELECT test_seq.nextval, test_seq.currval FROM dual;    NEXTVAL    CURRVAL ---------- ----------          7          7 SQL> SQL> drop sequence test_seq   2  / Sequence dropped.