What does this mean, and how can I get around it?
SELECT MySequence.CURRVAL FROM DUAL;
Result:
ORA-08002: sequence MySequence.CURRVAL is not yet defined in this session
CURRVAL. returns the current value of a sequence. NEXTVAL. increments the sequence and returns the next value. You must qualify CURRVAL and NEXTVAL with the name of the sequence: sequence.CURRVAL sequence.NEXTVAL.
The correct answer is c) Returns the last value across all nodes.
The Oracle NEXTVAL function is used to retrieve the next value in a sequence. The Oracle NEXTVAL function must be called before calling the CURRVAL function, or an error will be thrown. No current value exists for the sequence until the Oracle NEXVAL function has been called at least once.
mysequence.CURRVAL returns the latest value that was obtained from sequence mysequence in your session, and hence isn't defined until you have obtained a value using mysequence.NEXTVAL at least once in the session. The purpose of CURRVAL is to let you use the sequence value more than once in your code e.g.
insert into parent (parent_id, ...) values (mysequence.NEXTVAL, ...); insert into child (parent_id, ...) values (mysequence.CURRVAL, ...);
If CURRVAL just returned the last value obtained from the sequence by any session, then it would be useless in the above code, and in fact could lead to data corruption!
It turns out that you can't use CURRVAL until you have used NEXTVAL at least once in your session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With