Oracle Resume Auto-increment sequence (RPM)

Source: Internet
Author: User

Step: 1. Create a sequence
2. Create a trigger.

Syntax parsing:
Create sequence Tb_code_sequence
MinValue 1
MaxValue 999999999999999999999999999
Start with 11
Increment by 1
Cache 10;

CREATE OR REPLACE TRIGGER tb_code_increase before insert on Tb_code
For each ROW
Begin
Select Tb_code_sequence.nextval Into:New.ID from dual;
End

Create sequence tb_code_sequence---Creates a sequence named Tb_code_sequence.
MinValue 1---Minimum value is 1
MaxValue---Maximum value, you can set any positive integer value on MaxValue. When no value is set, the default is 999999999999999999999999999
Start with one---starting with the 11th record, starting from 1 when no records are recorded in the table
Increment by 1---increment value is 1, increments by 1 each time
Cache---Cache defines the size of the memory block that holds the sequence, which defaults to 20.

Create OR REPLACE TRIGGER tb_code_increase---Creating a trigger named Tb_code_increase
Before insert on Tb_code---defines when the trigger is fired, defined here to fire the trigger before inserting the Tb_code table
For each row---loop each row
Begin
Select Tb_code_sequence.nextval Into:New.ID from dual; ---The value returned by Nextval in the query sequence and returns it to the sequence.
End

Modify:
Some parts of the sequence can also be modified in use, but the SATRT with option cannot be modified.
Changes to the sequence affect only the resulting ordinal number, and the number that has been generated is unchanged.

Note that it is best to do these operations natively.

Oracle Resume Auto-increment sequence (RPM)

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.