Create auto-increment sequence trigger in Oracle

Source: Internet
Author: User
The following is an example and description of creating an auto-incrementing sequence for a field in an Oracle table.

The following is an example and description of creating an auto-incrementing sequence for a field in an Oracle table.

The following is an example of creating an auto-incrementing sequence for a field in an Oracle table.

/* ===================================================== ======================================= */
/* Set auto-increment sequence: annual job plan execution object table */
/* ===================================================== ======================================= */
Drop sequence SEQ_TBL_Y_PLAN_ACT_OBJ;
Create sequence SEQ_TBL_Y_PLAN_ACT_OBJ increment by 1 start with 1 MAXVALUE 9999999999 cycle nocache;
Create or replace trigger TRG_TBL_Y_PLAN_ACT_OBJ
Before insert on TBL_Y_PLAN_ACT_OBJ
FOR EACH ROW
BEGIN
SELECT SEQ_TBL_Y_PLAN_ACT_OBJ.NEXTVAL INTO: NEW. OBJ_ID from dual;
END;

This is a common format,

TBL_Y_PLAN_ACT_OBJ is the name of the table to be operated,

SEQ_TBL_Y_PLAN_ACT_OBJ is the name of the created auto-incrementing function;

9999999999 is based on the field length. In this example, the field length is 10;

OBJ_ID is the name of the field to be auto-increment in the table.

Recommended: Create and call Aggregate functions on your own in Oracle

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.