Caitlin_odowd
Caitlin_odowd

Reputation: 11

ORACLE APEX / SQL DEVELOPER: Cannot get PK to autoincrement

I am trying to implement my SQLDeveloper DB into Oracle APEX. I cannot figure out how to get the PK's in my table to auto-increment starting from a certain value (i.e. 400001). I have tried making triggers and sequences but when I try to add a row using a form in APEX, my PK increments from 40 for some reason.

Here is my APEX form outcome enter image description here

Here is how it inserts into SQL Developer enter image description here

Basically, can someone describe to me how I can edit the existing trigger, or create a sequence, that would make application_id of a new entry auto-increment by 1.

Thanks!

Upvotes: 0

Views: 144

Answers (1)

Littlefoot
Littlefoot

Reputation: 143053

Find max application_id:

select max(application_id) From your_Table;

Suppose it is 400010 (as screenshot suggests). Now recreate the sequence (presuming its name is seq_app):

drop sequence seq_app;
create sequence seq_app start with 400011 increment by 1 nocache;

Trigger is most probably OK, as you see values being inserted into the table.

Side note: sequences will be unique, but not necessarily gapless. CACHE (or NOCACHE) might affect that, but - for performance sake, you'd rather let Oracle cache sequence numbers (default is 20) which means that - if you don't use some of those cached numbers, they will be lost. I wouldn't worry, if I were you.

Upvotes: 0

Related Questions