Sequence processing in Oracle and DB2

Source: Internet
Author: User

1. sequence definition
ORACLE:

Create sequence <sequence_name>

Increment by <integer>

Start with <integer>

Maxvalue <integer>/nomaxvalue

Minvalue <integer>/nominvalue

Cycle/nocycle

Cache <#>/nocache

Order/noorder;

DB2:

Create sequence <sequence-Name>

As data-type default as integer
Start with <Numeric-constant>
Increment by <Numeric-constant> default value: increment by 1
Minvalue <Numeric-constant> | no minvalue defaults to no minvalue.
Maxvalue <Numeric-constant> | no maxvalue default value: No maxvalue
No cycle | no cycle by default
Cache <Numeric-constant> | no cache default cache 20
No order | order no order by default

2. Sequence values
Take the following value:
ORACLE: sequence. nextval
DB2: nextval for sequence or next value for sequence
Take the current value:
ORACLE: sequence. currval
DB2: previous value for sequence or prevval for sequence


3. Set the sequence start value
ORACLE: Get the next value. First set the step size (the difference between the next value and the set start value); then change the step size to the original value.
DB2: Alter sequence name restart with next value

3. Modify
ORACLE:
Alter maximum alter sequence <sequence_name> max value <integer>
Minimum value: Alter sequence <sequence_name> min value <integer> (This value must be smaller than the current value)
Modify the step size: Alter sequence <sequence_name> increment by <integer>;
Modify the cache value: Alter sequence <sequence_name> cache <integer> | nocache
Modify the cycle attribute: Alter sequence <sequence_name> <cycle | nocycle>
Modify the sorting attribute: Alter sequence <sequence_name> <order | noorder>

DB2:
Alter maximum alter sequence <sequence_name> max value <Numeric-constant> | no maxvalue
Minimum modification value: Alter sequence <sequence_name> min value <Numeric-constant> | no minvalue (This value must be smaller than the current value)
Modify the step size: Alter sequence <sequence_name> increment by <Numeric-constant>;
Modify the cache value: Alter sequence <sequence_name> cache <Numeric-constant> | no cache
Modify the cycle attribute: Alter sequence <sequence_name> <cycle | no cycle>
Modify the sorting attribute: Alter sequence <sequence_name> <order | no order>
New count: Alter sequence <sequence_name> restart | restart with <Numeric-constant>

3. Drop
ORACLE: drop sequence <sequence_name>;
DB2: drop sequence <sequence_name>;

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.