Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
CURRVAL is not "the latest value of the sequence". It is the value that NEXTVAL last gave to your own session. Until your session calls NEXTVAL, Oracle has nothing to return and raises ORA-08002, even if other sessions have used the sequence.
Below are three common ways to hit it, each run on Oracle 26ai Free. To get the ID of a row you just inserted, RETURNING id INTO is the simplest answer.
01CURRVAL right after creating the sequence, before any NEXTVAL
Right after CREATE SEQUENCE order_seq, SELECT order_seq.CURRVAL FROM dual fails with ORA-08002. user_sequences shows LAST_NUMBER 1, but that does not give this session a CURRVAL.
After INSERT INTO orders VALUES (order_seq.NEXTVAL, 'Pen') in the same session, order_seq.CURRVAL returned 1.
Setup
CREATE SEQUENCE order_seq;
CREATE TABLE orders (id NUMBER PRIMARY KEY, item VARCHAR2(20));Sequence created.
Table created.SELECT order_seq.CURRVAL FROM dual;SELECT order_seq.CURRVAL FROM dual
*
ERROR at line 1:
ORA-08002: Sequence ORDER_SEQ.CURRVAL is not yet defined in this session.
Help: https://docs.oracle.com/error-help/db/ora-08002/COLUMN sequence_name FORMAT A12
SELECT sequence_name, last_number FROM user_sequences;SEQUENCE_NAM LAST_NUMBER
------------ -----------
ORDER_SEQ 1
1 row selected.Call NEXTVAL first (in an INSERT or a SELECT) in the same session, then read CURRVAL.
INSERT INTO orders VALUES (order_seq.NEXTVAL, 'Pen');
SELECT order_seq.CURRVAL FROM dual;
ROLLBACK;1 row created.
CURRVAL
----------
1
1 row selected.
Rollback complete.02Reading CURRVAL in a new session after another session used NEXTVAL
One session inserted a row with order_seq.NEXTVAL and committed. A new session then ran SELECT order_seq.CURRVAL FROM dual and got ORA-08002. CURRVAL is per session; the NEXTVAL from the other session does not count. This often happens when the INSERT and the "get the new ID" query go through different connections.
MAX(id) showed 1 was stored, but that is not the value your session generated. The fix was to get the ID in the INSERT itself: INSERT … VALUES (order_seq.NEXTVAL, 'Note') RETURNING id INTO v_id printed new id = 2.
Setup
CREATE SEQUENCE order_seq;
CREATE TABLE orders (id NUMBER PRIMARY KEY, item VARCHAR2(20));
INSERT INTO orders VALUES (order_seq.NEXTVAL, 'Pen');
COMMIT;Sequence created.
Table created.
1 row created.
Commit complete.SELECT order_seq.CURRVAL FROM dual;SELECT order_seq.CURRVAL FROM dual
*
ERROR at line 1:
ORA-08002: Sequence ORDER_SEQ.CURRVAL is not yet defined in this session.
Help: https://docs.oracle.com/error-help/db/ora-08002/SELECT MAX(id) AS last_id FROM orders; LAST_ID
----------
1
1 row selected.SET SERVEROUTPUT ON
DECLARE
v_id orders.id%TYPE;
BEGIN
INSERT INTO orders VALUES (order_seq.NEXTVAL, 'Note') RETURNING id INTO v_id;
DBMS_OUTPUT.PUT_LINE('new id = ' || v_id);
ROLLBACK;
END;
/new id = 2
PL/SQL procedure successfully completed.03CURRVAL on the system sequence of an identity column
An identity column (GENERATED ALWAYS AS IDENTITY) uses a system sequence named ISEQ$$_ plus a number, which you can find in user_tab_identity_cols. Reading its CURRVAL in a session that has not inserted into the table yet fails with ORA-08002, with that ISEQ$$_ name in the message. The number differs per database, so search for "ISEQ$$ CURRVAL" rather than the exact name.
The fix is the same as for normal sequences: INSERT INTO members (name) VALUES ('Lee') RETURNING id INTO v_id returned new id = 2.
Setup
CREATE TABLE members (id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name VARCHAR2(20));
INSERT INTO members (name) VALUES ('Kim');
COMMIT;Table created.
1 row created.
Commit complete.DECLARE
v_seq VARCHAR2(128);
v_id NUMBER;
BEGIN
SELECT sequence_name INTO v_seq FROM user_tab_identity_cols WHERE table_name = 'MEMBERS';
EXECUTE IMMEDIATE 'SELECT ' || v_seq || '.CURRVAL FROM dual' INTO v_id;
END;
/DECLARE
*
ERROR at line 1:
ORA-08002: Sequence ISEQ$$_75259.CURRVAL is not yet defined in this session.
ORA-06512: at line 6
Help: https://docs.oracle.com/error-help/db/ora-08002/COLUMN column_name FORMAT A10
COLUMN sequence_name FORMAT A20
SELECT column_name, sequence_name FROM user_tab_identity_cols WHERE table_name = 'MEMBERS';COLUMN_NAM SEQUENCE_NAME
---------- --------------------
ID ISEQ$$_75259
1 row selected.If ORA-08002 names an ISEQ$$_ sequence, look it up in user_tab_identity_cols to see which table and column it belongs to.
SET SERVEROUTPUT ON
DECLARE
v_id members.id%TYPE;
BEGIN
INSERT INTO members (name) VALUES ('Lee') RETURNING id INTO v_id;
DBMS_OUTPUT.PUT_LINE('new id = ' || v_id);
ROLLBACK;
END;
/new id = 2
PL/SQL procedure successfully completed.FAQ
Why does CURRVAL fail when the sequence already has values?
CURRVAL is the last NEXTVAL of your own session. Values generated by other sessions, or by your earlier connection, do not count. Call NEXTVAL in the same session first.
How do I get the ID I just inserted in Oracle?
Use RETURNING id INTO on the INSERT. It works for both a sequence (order_seq.NEXTVAL) and an identity column, and was tested on this page.
What is the ISEQ$$_ sequence in ORA-08002?
It is the system sequence behind an identity column. SELECT column_name, sequence_name FROM user_tab_identity_cols shows which table it belongs to.
Can I use user_sequences.last_number instead of CURRVAL?
It is not the same value. Right after CREATE SEQUENCE it showed 1 while CURRVAL failed. To know the value you inserted, use RETURNING INTO or CURRVAL after NEXTVAL in the same session.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0