Oracle sequence parameters: nextval and currval

Source: Internet
Author: User

Oracle sequence parameters: nextval and currval. Nextval returns the next avaiable sequence value. it returns a unique value every time it is referenced, even for different users. currval obtains the current sequence value. open the first session and create a sequence: Call the nextval value before calling the value of currval.

SQL> create sequence myseq1  increment by 10 start with 120 maxvalue 9999 nocache nocycle;Sequence created.SQL> select myseq1.currval  from dual;select myseq1.currval  from dual       *ERROR at line 1:ORA-08002: sequence MYSEQ1.CURRVAL is not yet defined in this session

 

Therefore, call the nextval value first. The first value is 120.
SQL> select myseq1.nextval from dual;   NEXTVAL----------       120

 

Open the second session and the value of calling nextval will continue to increase to 130.
SQL> select myseq1.nextval from dual;   NEXTVAL----------       130

 

Return to the first session and call the value of currval,
SQL> select myseq1.currval from dual;   CURRVAL----------       120

 

We can see that the value of currval is not 130, or the value of the previous session. The value of nextval is called,
SQL> select myseq1.nextval from dual;   NEXTVAL----------       140

 

We can see that the value of nextval is added based on the second session. Therefore, the value of nextval is added every time it is called. The value of currval is the same as the current value of its own session.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.