Oracle:此会话中尚未定义序列MySequence.currval [英] Oracle: sequence MySequence.currval is not yet defined in this session

查看:97
本文介绍了Oracle:此会话中尚未定义序列MySequence.currval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么意思,我该如何解决?

What does this mean, and how can I get around it?

SELECT MySequence.CURRVAL FROM DUAL;

结果:

ORA-08002:此会话中尚未定义序列MySequence.CURRVAL

ORA-08002: sequence MySequence.CURRVAL is not yet defined in this session

推荐答案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆