I'm trying to create a table where one of the columns will contain autoincrementing numbers. Is there some other way of doing that instead of creating sequence for each row? The rows will be dynamically added/removed and the sequence needs to be resetable.
Table should look like this:
[Foreign_Key] [Sequence_State]
A 0
B 0
C 0
And when I call something like this(pseudocode):
getNextNumber('A');
getNextNumber('A');
getNextNumber('A');
getNextNumber('B');
getNextNumber('B');
the state of the table should change to this:
[Foreign_Key] [Sequence_State]
A 3
B 2
C 0
I guess I could go with PL/SQL function which would create the sequence for the Foreign_Key
if it doesn't exist, increment and update the Sequence_State
. But this all seems a bit clunky and I'm wondering if there's some better way to do that.