Oracle sequence Sequence

Source: Internet
Author: User

sequence : Is an object provided by Oracle that produces a unique numeric value, primarily for use with a single primary key of a table.

To Create a sequence :

Create sequence seq_name//naming

Start with 1//initial value

Increment by 1//increment value

MinValue 1//minimum value, default, system default

MaxValue 999999999999999999//maximum value, default, system default value

nocache//cache Cache is not cached is a one-time system to read how many values put into the current session of the sequence pool for use to improve efficiency, but easy to jump

cycle//loop nocycle does not cycle when an object reaches the Extremum, does the iteration begin Again

The order//guarantees the value of the read sequence, consistent with the order of the connection session, before the value is first connected. Default Value Noorder

;

Use sequence:

Select sequence name. Currval from dual view current sequence values

Select sequence name. Nextval from dual View the number of the next sequence, which automatically adds an increment to the current sequence

Precautions, first use, first nextval otherwise error "appears ORA-08002: sequence Xxxxxxx.currval has not yet been defined in this process. "

To modify a sequence:

alter sequence seq_name MaxValue 9999999;

Note: You cannot change the maximum value to 1000 if the change is to conform to logic, such as when the next number of the sequence is 10000.

To delete a sequence:

drop sequence seq_name

Comprehensive case

MySQL table primary key auto-increment effect with Oracle Trigger

Create a Trigger

Create or Replace trigger trg_t_name//define triggers

Before insert on T_name for each row//new record operation
Begin

Select Seq_name.nextval into:new.id from dual;//application sequence
End

Reference : http://docs.oracle.com/cd/E11882_01/server.112/e41084/toc.htm

Oracle 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.