Select sequence. currval reported error ORA-08002: sequence XXXX is not defined in this process, sequencecurrval

Source: Internet
Author: User

Select sequence. currval reported error ORA-08002: sequence XXXX is not defined in this process, sequencecurrval

Scenario Description:

1. Create a table named S_DEPART

-- Create tablecreate table S_DEPART(  departid    INTEGER not null,  departname  NVARCHAR2(40) not null,  departorder INTEGER default 0)
2. Create a sequence named S_DEPART_S

CREATE SEQUENCE S_DEPART_S MINVALUE 1MAXVALUE 9999999999999999999999START WITH 1INCREMENT BY 1NOCACHE;
3. Insert a record to the table below

insert into S_Depart(departid,Departname,Departorder)VALUES(S_DEPART_S.CURRVAL,'12345',1);
The following error occurs:

Error ORA-08002: sequence XXXX not defined in this process

Error analysis: The CURRVAL of the sequence must be initialized with NEXTVAL, and then CURRVAL can be used.

Solution: First initialize with NEXTVAL:

<pre name="code" class="sql">insert into S_Depart(departid,Departname,Departorder)VALUES(S_DEPART_S.NEXTVAL,'12345',1);

In this case, we can query the value of the sequence S_Depart_s: 

SELECT S_DEPART_S.CURRVAL FROM dual;
We can see that the current value of the S_Depart_s sequence is 2.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.