How to create an Oracle Auto-increment or identity field _ Oracle Application

Source: Internet
Author: User
SQL Server, ACCESS, and MYSQL both have an auto-increment field, which is usually used for primary keys or index keys. However, in ORACLE, this field type is not provided (not actually a field type), but we often need this function.

SQL SERVER, ACCESS, and MYSQL both have an auto-increment field, which is usually used for primary keys or index keys. However, in ORACLE, this field type is not provided (not actually a field type), but we often need this function.

The following shows an implementation method of ORACLE. Two steps are required:
1. create sequence create [or replace] SEQUENCE sequence_identity start with initial seed increment by step MAXVALUE upper bound [NOMAXVALUE] NOCYCLE [empty]
2. create trigger create [or replace] TRIGGER trigger_identity before insert on table_name for each row begin select sequence_identity.NEXTVAL INTO: new. column_name from dual; END;
Note:
To avoid sequence conflicts with the same name, we recommend that you use the sequence_identity naming method.
SEQ_UserName_TableName_SequenceName format
The trigger_identity naming method.

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.