What will happen when the sequence reaches the maximum value in Oracle?

Source: Internet
Author: User

What is the problem when the sequence reaches the maximum value in Oracle? The sequence is a database object provided by oracle to generate a series of unique numbers. The sequence will automatically generate an ascending sequence number, to automatically provide unique primary key values, the series can be used in multiple concurrent user environments and can generate non-repeated sequential numbers for all users, without any additional I/O overhead. Creating a sequence is the same as creating a view. It does not occupy the actual storage space, but stores its definition information in the data dictionary. You must have the create sequence system permission when creating a sequence. Syntax format: create sequence seq_name [start with n] [minvalue n | nomainvalue] [maxvalue n | nomaxvalue] [cache n | ncache] [cycle | nocycle] [order | noorder]; description: seq_name: sequence name. Increment: This clause is optional, indicating the Increment of the sequence. A positive number generates an ascending sequence, and a negative number generates a descending sequence. The default value is 1 minvalue: an optional clause that determines the minimum value generated by the sequence. Maxvalue: an optional clause that determines the maximum value generated by the sequence. Start: an optional clause that specifies the start position of the sequence. By default, the starting value of the ascending sequence is minvalue, and the starting value of the descending sequence is maxvalue. Cache: This option determines whether serial numbers are pre-allocated and stored in the memory. Cycle: an optional keyword. When the sequence reaches the maximum value (maxvalue) or the minimum value (minvalue), it can be reset and continue. If the limit is reached. The next data generated will be the minimum or maximum values. If you use the no cycle option, an error is returned if you attempt to obtain the next value after the sequence reaches the maximum or minimum value. Order: This option ensures that the generated sequence values are generated in order. For example, order can ensure that the first request gets 1, the second request gets 2, and so on. NOODDER only guarantees the uniqueness of the sequence value, but does not guarantee the order in which the column values are generated. Example: create sequence seq_dept maxvalue 99 -- maximum value generated by the sequence. Start with 50 -- increment by 10 starting from 50 -- increase the number of 10 serial numbers in cache by 10 each hop; -- pre-allocate 10 in the system. The serial numbers generated in the future are 50, 60, 70, 80, and 90. Note: when using a sequence, the NexVal and CurrVal pseudo columns of the sequence are required. Nextval returns the next serial number generated by the sequence, while the pseudo column currval returns the current serial number of the sequence. Note that the pseudo-column nextval must be used when the sequence is referenced for the first time. Example: insert into scott. dept (deptno, dname, loc) values (seq_dept.nextval, 'Development ', default); after executing the preceding sentence, a piece of data is inserted into the dept table, in addition, the deptno column uses the serial number generated by the deptno_seq sequence. In addition, if you want to determine the current serial number, you can use the pseudo column currval. Example: select seq_dept from dual;

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.