I need to get the next available id in a sequence, using GORM or native query.
How can I do this?
I’m using oracle.
UPDATE:
I need this value BEFORE insert, because my row will use this value.
I have table called IMAGE, with column FILE_NAME, like this:
- ID | FILE_NAME
- 123 | foo_bar_123.png
- 124 | xxx_yyy_124.png
Tks a lot.
Why do you need the value before the insert? Could you get the information as part of the insert using the
RETURNINGclause, i.e.Or access it after the insert using
The
currvalof a sequence returns the most recent value of the sequence produced in the current session so it is actually thread-safe. Since sequences are designed to provide numbers in a highly concurrent environment, you cannot in general find out what thenextvalis going to be unless you actually fetch thenextval. Even if you could, there is no guarantee that another thread won’t come along and get the value you peeked at before yourINSERTtook place so it wouldn’t be safe to peek at thenextvalin a multi-user environment.