Skip to content
Advertisement

How to retrieve the current value of an oracle sequence without increment it?

Is there an SQL instruction to retrieve the value of a sequence that does not increment it.

Thanks.

EDIT AND CONCLUSION

As stated by Justin Cave It’s not useful to try to “save” sequence number so

is good enough to check a sequence value.

I still keep Ollie answer as the good one because it answered the initial question. but ask yourself about the necessity of not modifying the sequence if you ever want to do it.

Advertisement

Answer

You can get a variety of sequence metadata from user_sequences, all_sequences and dba_sequences.

These views work across sessions.

EDIT:

If the sequence is in your default schema then:

If you want all the metadata then:

Hope it helps…

EDIT2:

A long winded way of doing it more reliably if your cache size is not 1 would be:

Just beware that if others are using the sequence during this time – they (or you) may get

Also, you might want to set the cache to NOCACHE prior to the resetting and then back to its original value afterwards to make sure you’ve not cached a lot of values.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement