Establish and query Sequence in Oracle Database

Source: Internet
Author: User

The relevant Oracle Database Sequence information is as follows:

Create Sequence syntax

Create sequence <schema>. <table_name> _ s
Increment by 1
Start with 1
Max value 99999999999999999999
Minvalue 1
Nocycle;
 
Where:
Incerment: value added each time
Start: Sequence start value
Maxvalue: Maximum Sequence Value
Nocycle: When the Sequence reaches the maximum value, it does not start with the same Sequence.

Get the next Sequence Value

Select <Sequence_name>. nextval [@ db_link]
From dual;

Query the current Sequence Value

Syntax 1:
Select <Sequence_name>. currval [@ db_link]
From dual;
 
Mark: If "Current DB Session" has not executed nextval, run currval first.
ORA-08002: sequence DB_SESSION_ID.CURRVAL is not yet defined in this session error.
 
Syntax 2:
Select last_number-1
From all_sequences
Where sequence_name = '<Sequence_name> ';

Modify Sequence

For example, Alter Sequence <Sequence_name> MaxValue 999999999999999;

Notes

1) Sequence cannot be directly used after "equation: =". For example, vID: = tomSeq. nextval;
2) Sequence can be directly used in "SQL". For example: insert into tomTable values (tomSeq. nextval ,...);

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.