Select Sequence.currval times wrong ORA-08002: sequence xxxx has not been defined in this process

Source: Internet
Author: User

Scenario Description:

1. We create a table with the table named S_depart

--Create tablecreate table S_depart (  departid    INTEGER not NULL,  departname  NVARCHAR2 (+) NOT NULL,  departorder INTEGER default 0)
2. Create a sequence sequence with the name s_depart_s

CREATE SEQUENCE s_depart_s MINVALUE 1MAXVALUE 9999999999999999999999START with 1INCREMENT by 1NOCACHE;
3. Below we insert a record into the table

Insert into S_depart (departid,departname,departorder) VALUES (s_depart_s.currval, ' 12345 ', 1);
at this point, the following error occurs:

Error ORA-08002: Sequence XXXX has not been defined in this process

Error Analysis: The currval of the sequence sequence must first be initialized with Nextval, and later it can be used currval.

Workaround: Initialize with Nextval first:

<pre name= "code" class= "SQL" >insert into S_depart (departid,departname,departorder) VALUES (S_depart_s.nextval, ' 12345 ', 1);

At this point we can query the value of the sequence sequence s_depart_s:

SELECT S_depart_s.currval from dual;
From what we can see the current value of the s_depart_s sequence is 2


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Select Sequence.currval times wrong ORA-08002: sequence xxxx has not been defined in this process

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.