The implementation process of Oracle database Auto-Growth column

Source: Internet
Author: User

1. Create a sequence

--Create sequence

Create sequence Innerid

MinValue 1

MaxValue 99999999999999

Start with 1

Increment by 1

Cache 20

Order

2.--innerid.currval refers to the current sequence

--innerid.nextval refers to the next sequence

Insert into admin values (innerid.nextval, ' a ');

Insert into admin values (innerid.nextval, ' B ');

Insert into admin values (innerid.nextval, ' C ');

Insert into admin values (innerid.nextval, ' d ');

CREATE TABLE Admin

(ID varchar2 (), name VARCHAR2 (10));

--constant insertion of the next value of the sequence.

3. Create a trigger (note: The default value for ID cannot be set here is Innerid.nextval)

CREATE OR REPLACE TRIGGER ADMIN_TG

Trigger for--admin ID

Before INSERT on admin for each ROW

BEGIN

SELECT Innerid. Nextval INTO:NEW.id from DUAL;

END;

The test statements are as follows:

Insert into admin (username) VALUES (' Zdz ');

If you successfully insert the data, and then look at the data, you can see that the ID has grown automatically and this problem is resolved!

The implementation process of Oracle database Auto-Growth column

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.