环境
Oracle 11.2.0 + SQL Plus
问题
查询Sequence的当前值出现以下错误:
SQL> SELECT seq_WGB_Test2.CURRVAL FROM dual;
SELECT seq_WGB_Test2.CURRVAL FROM dual
*
第 1 行出现错误:
ORA-08002: 序列 SEQ_WGB_TEST2.CURRVAL 尚未在此会话中定义
解决
首先创建一个测试序列:
SQL> CREATE SEQUENCE seq_WGB_Test2
2 INCREMENT BY 1
3 START WITH 1000;
序列已创建。
然后查询当前值:
SQL> SELECT seq_WGB_Test2.CURRVAL FROM dual;
SELECT seq_WGB_Test2.CURRVAL FROM dual
*
第 1 行出现错误:
ORA-08002: 序列 SEQ_WGB_TEST2.CURRVAL 尚未在此会话中定义
调用NEXTVAL后再次查询当前值:
SQL> SELECT seq_WGB_Test2.NEXTVAL FROM dual;
NEXTVAL
----------
1000
SQL> SELECT seq_WGB_Test2.CURRVAL FROM dual;
CURRVAL
----------
1000
SQL>