问题描述
这是什么意思,我该如何解决?
What does this mean, and how can I get around it?
SELECT MySequence.CURRVAL FROM DUAL;
结果:
推荐答案
mysequence.CURRVAL返回在您的会话中从序列mysequence获得的最新值,因此直到您具有在会话中至少使用一次mysequence.NEXTVAL获得了一个值. CURRVAL的目的是让您在代码中多次使用序列值,例如
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, ...);
如果CURRVAL刚刚返回了通过 any 会话从序列中获得的最后一个值,那么在上面的代码中它将是无用的,并且实际上可能导致数据损坏!
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!
这篇关于Oracle:此会话中尚未定义序列MySequence.currval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!