Use of sequence sequences in Oracle __oracle

Source: Internet
Author: User

A sequence is a database object that can be used to generate a unique integer. You typically use sequences to automatically generate primary key values.

1) Establish sequence command

CREATE SEQUENCE [user.] Sequence_name
[Increment by n]
[Start with N]
[MaxValue n | nomaxvalue]
[MinValue n | nominvalue];
[Nocycle]--
INCREMENTBy: Specifies the interval between serial numbers, which can be positive or negative integers, but not 0. The sequence is ascending. When this clause is omitted, the default value is 1.
STARTwith: Specifies the first serial number generated. In ascending order, the sequence can start with a value that is larger than the minimum value, and the default value is the minimum value for the sequence. For descending, the sequence can start with a value smaller than the maximum value, and the default value is the maximum value for the sequence.
MAXVALUE: Specifies the maximum value that the sequence can generate.
Nomaxvalue: Specifies the maximum value of 1027 for ascending order, and the maximum value of 1 for descending.
MinValue: Specifies the minimum value for the sequence.
Nominvalue: Specifies a minimum value of 1 for ascending order. Specify a minimum value of-1026 for descending order.
nocycle: Cumulative, not loop 2) Change sequence command

altersequence [user.] Sequence_name
[INCREMENT by N]
[MAXVALUE n| Nomaxvalue]
[MinValue N | Nominvalue];
Modify the sequence to:
Modifies the increment of future sequence values.
Sets or undoes the minimum or maximum value.
Change the number of buffer sequences.
Specifies whether the serial number is ordered.

Attention:
1, the first time Nextval return is the initial value
2, you can alter all sequence parameters except start to. If you want to change the start value, you must drop sequence and then re-create.

3) Delete sequence command

DROP SEQUENCE [user.] Sequence_name;
Used to delete a sequence from the database. 4) His experiment

4.1 Create a statement with a serial number:

--Create sequence
Create sequence Ncme_question_seq
MinValue 1
MaxValue 999999999999
Start with 1
Increment by 1
NoCache;

4.2) The use of serial numbers in sql:

SELECT Ncme_question_seq.nextval from dual
SELECT Ncme_question_seq. Currval from dual


Dual itself is a word, not an abbreviation of a phrase. The noun means logarithm, and the adjective is double. Dual refers to dual table in Oracle, a single row of virtual tables.
1:dual table--A special kind of one-row and one-column database table;
2:dual is a table which are created by Oracle along with the data dictionary. It consists of exactly one column whose the name is dummy and one record. The value of that, the record is X.
3:note that the outer query references the dummy table called dual the dual table are used in Oracle when your need to run S QL that does not logically have a table 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.