Oracle:此会话中尚未定义序列 MySequence.currval
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/809247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle: sequence MySequence.currval is not yet defined in this session
提问by Doug
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
ORA-08002: 此会话中尚未定义序列 MySequence.CURRVAL
回答by Tony Andrews
mysequence.CURRVAL returns the latest value that was obtained from sequence mysequence in yoursession, 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.
mysequence.CURRVAL返回从序列mysequence中获得的最新值您的会话,因此没有定义,直到你获得使用mysequence.NEXTVAL至少一次会话的值。CURRVAL 的目的是让您在代码中多次使用序列值,例如
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 anysession, then it would be useless in the above code, and in fact could lead to data corruption!
如果 CURRVAL 只是返回任何会话从序列中获取的最后一个值,那么它在上面的代码中将毫无用处,实际上可能会导致数据损坏!
回答by Doug
It turns out that you can't use CURRVAL until you have used NEXTVAL at least once in your session.
事实证明,在会话中至少使用过一次 NEXTVAL 之前,您不能使用 CURRVAL。
回答by HainKurt
use this
用这个
select sequence_name,
to_char(min_value) min_value,
to_char(max_value) max_value,
increment_by,
cycle_flag,
order_flag,
cache_size,
to_char(Last_number) last_number
from user_sequences
where sequence_name='MYSEQUENCE'
回答by Rob van Wijk
Doug,
道格,
The real question is why you need the currval when you haven't used a nextval in your session? You can look at the column LAST_NUMBER of the USER/ALL/DBA_SEQUENCES view, but think of concurrency issues when you start to use that.
真正的问题是,为什么在会话中没有使用 nextval 时还需要 currval?您可以查看 USER/ALL/DBA_SEQUENCES 视图的 LAST_NUMBER 列,但是当您开始使用它时,请考虑并发问题。
Regards, Rob.
问候,罗布。
回答by Tarun Nigam
select * from user_sequences where sequence_name='SEQ_V_WORKORDER_RECNO';
in the above query SEQ_V_WORKORDER_RECNO
my sequence name replace it by your sequence name
在上面的查询中,SEQ_V_WORKORDER_RECNO
我的序列名称替换为您的序列名称