How to have multiple sequences depending on the value of specific column in Oracle
; that is, new Sequence
for each different value for that column.
Table is:
CREATE TABLE TEST
(
TYPE VARCHAR2(20) NOT NULL ,
SERIAL_NUM INT NOT NULL,
CONSTRAINT TEST_PK PRIMARY KEY
(
TYPE,
SERIAL_NUM
)
ENABLE
);
This Link: How to create id with AUTO_INCREMENT on Oracle?
shows how to generate auto incremental Sequence
assuming that the primary key is one attribute. How to have separate Sequence
for each unique value in TYPE
column?
I was thinking of creating multiple Sequences
for each possible value in TYPE
, creating Trigger
for each Sequence
and adding if
condition for flirting based on TYPE
column value. But, I realized that this is not the right approach since I need to create new Sequence
and Trigger
for any new TYPE
added.
A sample data should be similar to the following:
TYPE SERIAL_NUM
X 1
X 2
X 3
Y 1
Y 2
Z 1
Z 2
Z 3
Z 4
Any suggestions...