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