Avatar of annihil8
annihil8
 asked on

Reset Oracle Sequence

Hi experts,

I'm using the following code to reset a sequence and for test purposes I do a select of the next.val.
When executing I get the following error :

select seq_check_types.nextval from dual
ORA-08004: sequence SEQ_CHECK_TYPES.NEXTVAL goes below MINVALUE and cannot be instantiated

Does anybody got an idea how to solve this? i'm new to Oracle and i'm not familiar with it.
CREATE OR REPLACE PROCEDURE RESET_SEQUENCE (
seq_name IN VARCHAR2, startvalue IN PLS_INTEGER, incrementvalue IN PLS_INTEGER) IS
BEGIN
  EXECUTE IMMEDIATE 'DROP SEQUENCE ' ||seq_name;
  EXECUTE IMMEDIATE 'CREATE SEQUENCE ' ||seq_name|| 'START WITH' ||startvalue|| 'INCREMENT BY' || incrementvalue || 'NOMAXVALUE';
END RESET_SEQUENCE;
/
 
DELETE FROM check_types;
RESET_SEQUENCE(seq_check_types,1,1);
select seq_check_types.nextval from dual;

Open in new window

Oracle Database

Avatar of undefined
Last Comment
NeilChak

8/22/2022 - Mon
Raja Jegan R

The resolution for ORA-08004 is to alter the sequence so that a new value can be requested

Use the syntax below:

ALTER SEQUENCE [schema.]sequence_name MINVALUE 1

This will solve you out.
Raja Jegan R

The prime reason why you obtain this error is that your sequence reached the MAX value and you have to alter it again to start with the new MIN value.
SOLUTION
Ivo Stoykov

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Shaju Kumbalath

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
NeilChak

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes