Set up an auto-growing identity column for a table in Oracle

Source: Internet
Author: User

--Create sequence Create sequence Innerid minvalue 1 maxvalue 99999999999999 start with 1 increment by 1 cache order;

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

CREATE TABLE admin (ID varchar2 (), name VARCHAR2 (10));

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 '); --constant insertion of the next value of the sequence.

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

CREATE OR REPLACE TRIGGER admin_tg--admin ID of the trigger before INSERT on admin for each ROW BEGIN SELECT Innerid. Nextval INTO:NEW.id from DUAL; END;

Test statement

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

Set up an auto-growing identity column for a table in Oracle

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.