user2126932
user2126932

Reputation: 1

JDBC Error : java.sql.SQLException: ORA-08002: sequence is not yet defined in this session

Below is my sequence that i created :

CREATE SEQUENCE  SEQ_SURVEY INCREMENT BY 1 START WITH 1 NOCACHE  NOCYCLE ;

in my JDBC Code, I am using :

String currentValueFromSequence = "SELECT SEQ_SURVEY.CURRVAL FROM DUAL";
PreparedStatement getCurrValFromSeq = con.prepareStatement(currentValueFromSequence);

ResultSet getSurveyResponseID = getCurrValFromSeq.executeQuery();

Its throwing an error stating that :

java.sql.SQLException: ORA-08002: sequence SEQ_SURVEY.CURRVAL is not yet defined in this session

I am not able to understand why this code is not running in my QA Environment whereas this code ran perfectly fine in my Dev Environment.

Can any expert provide their suggestion ?

Upvotes: 0

Views: 1174

Answers (1)

Khayyam Sadigov
Khayyam Sadigov

Reputation: 176

You need to call NEXVAL first. That's why you are getting the error.

SELECT SEQ_SURVEY.NEXTVAL FROM DUAL

The Oracle NEXTVAL function is used to retrieve the next value in a sequence. The Oracle NEXTVAL function MUST BE called before calling the CURRVAL function, or an error will be thrown. The Oracle CURRVAL function is used to access the current value of the specified sequence. Note that CURRVAL can only be used if NEXTVAL has been referenced in the current user session at least once.

Upvotes: 1

Related Questions