Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Referencing currval before nextval.

ProhanJun 4 2008 — edited Jun 5 2008
In the code for my APEX app, I need to check the currval of a sequence and return it to an item on the form.
If the sequence has not yet been given its first value (with NextVal), I want to return the number 1 to the item. HOWEVER, in that scenario, when I use currval, a "WHEN OTHERS" exception will be raised.
But I can't just assign 1 to the item if that exception is raised because it might be raised for other reasons as well.
And I can't use NextVal either because I don't want to increment the sequence, which would put it out of sync if the user did not go through with his intended action.
So, how do I check the value of a sequence without incrementing it and at the same time make sure that if it has not yet been given its initial value, I can set it to 1?

Here is some sample code:
SELECT tags_s.CURRVAL
INTO v_tag
FROM dual;
[The exception will be raised if this sequence has not yet been used. In that case, I want to return 1.]


EXCEPTION
WHEN OTHERS THEN
RETURN 1;
[But I can't do this because the exception may be called
for other reasons. If it is, returning 1 would be incorrect. And I don't know any predefined exceptions that are raised when a currval is used before nextval. Do you? If there were, that would solve the problem.]

I'd appreciate some suggestions. Thanks.

Message was edited by:
Prohan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 3 2008
Added on Jun 4 2008
4 comments
1,930 views