I have a big problem. I need to know the next value of an oracle sequence without changing it.
If I use sequence.NEXTVAL
, I get what I need. The problem is that the value changed, so the next record will get this value + 1 and it's not good for me.
I know I can use sequence.CURRVAL
and it's great because it does not change the value, but in case of no records, it's not working and in this case the sequence value can be any number (and not only 1 cause the sequence value steel exist).
Please help me to find a solution.
Thank you vary much !!!!!
You should definitely not rely on never missing a value in a sequence, as they optimise for concurrency over sequential numbering. There are quite a few situations in which a number can be "lost".
Furthermore, the value visible in the dba_sequences may not be the actual next value, as the numbers are assigned from an in-memory cache. The underlying sequence metadata table has no data on the usage of that cache. You should also bear in mind that in a RAC system each instance has its own cache of sequence numbers.
You might describe the problem you are trying to solve, as it could be that sequences are not an appropriate mechanism for you.