Cache problems in sequence Sequence

Source: Internet
Author: User

The sequence creation syntax in Oracle is as follows:

CREATE SEQUENCE [ schema. ] sequence   [ { INCREMENT BY | START WITH } integer   | { MAXVALUE integer | NOMAXVALUE }   | { MINVALUE integer | NOMINVALUE }   | { CYCLE | NOCYCLE }   | { CACHE integer | NOCACHE }   | { ORDER | NOORDER }   ]...;

In the sequence creation statement,

The cache clause preallocates a set of sequence numbers and keeps them in memory so that sequence numbers can be accessed faster. when the last of the sequence numbers in the cache has been used, the database reads another set of numbers into the cache.

The database might skip sequence numbers if you choose to cache a set of sequence numbers. for example, when an instance abnormally shuts down (for example, when an instance failure occurs or a shutdown abort statement is issued), sequence numbers that have been cached but not used are lost.

-- Let's test the sequence as follows:

SQL> Create sequence S1
2 start with 10
3 increment by 10
4 maxvalue 1000000000000000000000
5 cycle
6 Cache 10;

SQL> select s1.nextval from dual;

Nextval
----------
10

SQL> shutdown abort

SQL> startup

SQL> select s1.nextval from dual;

Nextval
----------
110

SQL>/

Nextval
----------
120

SQL> shutdown immediate

SQL> startup

SQL> select s1.nextval from dual;

Nextval
----------
130

It can be seen that when the database is shut down abnormally, all the pre-stored sequence values in the cache are lost. In this example, 10 values are pre-stored, from 10 to 100 ,. After the database is restarted, the next sequence value starts from 120. When the database is shut down normally, the pre-stored sequence values in the cache will not be lost.

Cache problems in sequence Sequence

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.