Common Oracle database objects-Sequence

Source: Internet
Author: User

Common Oracle database objects-Sequence

1. sequence: a database object provided by oacle for generating a series of unique numbers.

A) sequence features

I. The unique value is automatically provided.

Ii. shared object

Iii. Mainly used to provide the primary key value

Iv. Loading Sequence values into memory improves access efficiency

B) sequence definition

Create sequence Sequence

[Increment by N]

[Start with N]

[{Maxvalue n | nomaxvalue}]

[{Minvalue n | nominvalue}]

[{Cycle | nocycle}]

[{Cache n | cocache}];

Ii. Sequence Creation

A) You must have the create sequence or create any sequence permission to create a sequence.

B) sequence creation syntax

Create SequenceSequence// Create a sequence name

[IncrementN] // The incremental sequence value is n. If n is positive, it increases. If n is negative, it decreases by 1 by default.

[StartN] // Start value. The default value of increment is minvalue and the value of increment is maxvalue.

[{MaxvalueN|Nomaxvalue}] // Maximum value

[{MinvalueN|Nominvalue}] // Minimum value

[{Cycle |Nocycle}] // Loop/non-Loop

[{CacheN| Nocache}]; // It is allocated to the memory.

C) Notes

I. nextval returns the next valid value in the sequence, which can be referenced by any user.

Ii. Store the current value of the sequence in currval

Iii. nextval should be specified before currval, and both should be valid at the same time

Iii. Sequence usage

A) Loading Sequence values into memory improves access efficiency

B) The sequence has cracks in the following circumstances:

I. rollback

Ii. system exceptions

Iii. Multiple tables use the same sequence at the same time

C) if you do not load the sequence value into the memory (nocache), you can use the user_sequences table to view the current valid values of the sequence.

4. Modify the sequence

A) modify the sequence increment, maximum value, minimum value, loop option, or whether to load the memory.

Example: Alter sequence dept_deptid_seq

Increment by 20

Max value 999999

Nocache

Nocycle;

Sequence altered.

 

B) Considerations

I. It must be the sequence owner or have the alter permission on the sequence.

Ii. Only future sequence values will be changed

Iii. Changing the initial values of a sequence can only be achieved by deleting the sequence and recreating the sequence.

Iv. Use the drop sequence statement to delete a sequence

V. After deletion, the sequence cannot be referenced again

 

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.