ORA-08002 & SEQUENCE

同事来问测试环境上的一个sequence.currval 为什么取不到当前值。我说你试试nextval就能取到了。

 

metalink  ORA-8002 When Selecting CURRVAL From Sequence [ID 1019173.102]

文章中说到:

Before you can access CURRVAL for a sequence, you must first initialize the
sequence with NEXTVAL.

下面做个小的实验:

 

SQL> CREATE SEQUENCE t_sequence  START WITH 1000;

Sequence created

 

创建序列后,直接使用currval取序列的当前记录,返回错误:ORA-08002

SQL> SELECT t_sequence.CURRVAL  FROM DUAL;

SELECT t_sequence.CURRVAL  FROM DUAL

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

 

SQL> SELECT t_sequence.nextval  FROM DUAL;

   NEXTVAL
----------
      1000

 

 

SQL> SELECT t_sequence.CURRVAL  FROM DUAL;

   CURRVAL
----------
      1000

 

SQL> SELECT t_sequence.nextval  FROM DUAL;

   NEXTVAL
----------
      1001

 

你可能感兴趣的:(ORA-08002 & SEQUENCE)