0

Not sure if this is possible and I may be misunderstanding sequences here...

I have an SQL script that is adding data to a table in oracle. Each table has a primary key which is generated via a sequence.

I am currently calling

MY_SEQ.NEXTVAL

to get hte next sequence value.

Now I had a problem earlier where some lines had been added in the DB which were not added via the sequence. The IDs were manually added via the SQL script. This meant that when my

MY_SEQ.NEXTVAL

ran it failed because it generated a sequnence number that was already in use as a primary key.

Is there a way to reconcile the sequences in oracle and the ids that are currently in the database? Currently I am having to check at the beginning which is not ideal. I want all the table to be used with sequences. Can I get the sequence to consider the existing ID?

Any ideas? Is this possible?

Thanks

1 Answer 1

2

You can alter the sequence to have the nextval higher then the max id in your table:

select max(id) from your_table;

alter sequence my_seq increament by <the amount to go beyond your max ID>;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.