oracle-sequence (SEQUENCE)-____oracle

Source: Internet
Author: User
Sequence (SEQUENCE)
A sequence is a database object that can be used to generate a unique integer. The main code value is generated automatically by using a sequence.
The value of a sequence is automatically generated by a special Oracle program, so the sequence avoids the performance bottleneck caused by implementing the sequence in the application layer.
The Oracle sequence allows multiple serial numbers to be generated at the same time, and each serial number is unique. When a serial number is generated, the sequence is incremented,
Commit or rollback independent of the transaction. Allows you to design a default sequence without specifying any clauses. The sequence is an ascending sequence, starting from 1, with an increment of 1, with no upper limit.

1) Establish sequence command
CREATE SEQUENCE [user.] Sequence_name
[Increment by n]
[Start with N]
[MaxValue n | nomaxvalue]
[MinValue n | nominvalue];
INCREMENT by: 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.
START with: 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.

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.
3) Delete sequence command
DROP SEQUENCE [user.] Sequence_name;
Deletes a sequence from the database.
////////////////////////////////////////////////////////////////////////////////////////
To create a statement with a serial number:

CREATE SEQUENCE Exam_no_seq
START with 1484
MAXVALUE 9999999999
MinValue 1
CYCLE
CACHE 20
Noorder;
/////////////////////////////////////////////////////////////////////////////////////////
The use of the serial number in PB:

String V_exam_no
Get the requisition number
SELECT Exam_no_seq.nextval Into:v_exam_no from dual
Using Ghis_database;
If Ghis_database. Sqlcode<>0 Then
MessageBox ("", "Error checking serial number")
Return
End If

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.