1

To reset an Oracle sequence, I follow the following temporary way. Let's say, I have a table named TEMP_TABLE with a sequence associated with it.

The following SQL produces 22 as the sequence next value (only in this case).

SELECT TEMP_TABLE_SEQ.NEXTVAL from DUAL;

The following statement decreases the cache size to SEQUENCE.MINVALUE.

ALTER SEQUENCE TEMP_TABLE_SEQ INCREMENT BY -21;

Next, I'm performing a dummy select that retrieves 1 as the sequence value.

SELECT TEMP_TABLE_SEQ.NEXTVAL from DUAL;

I'm now resetting the cache size to 1.

ALTER SEQUENCE TEMP_TABLE_SEQ INCREMENT BY 1;

So that the following statement,

SELECT TEMP_TABLE_SEQ.NEXTVAL from DUAL;

gives me 2 as the next sequence value and so on.


In PostgreSQL server, the following only one statement is sufficient to reset a sequence.

ALTER SEQUENCE TEMP_TABLE_SEQ RESTART WITH 0;

Is there such a fair way in Oracle (10g) to reset a sequence?

Tiny
  • 27,221
  • 105
  • 339
  • 599
  • possible duplicate of [How do I reset a sequence in Oracle?](http://stackoverflow.com/questions/51470/how-do-i-reset-a-sequence-in-oracle) – DCookie Feb 06 '13 at 04:50

1 Answers1

-1

How about this :

  1. Drop the sequence

     DROP TEMP_TABLE_SEQ;
    
  2. Recreate the sequence

     CREATE SEQUENCE TEMP_TABLE_SEQ
     MINVALUE 1
     MAXVALUE  999999999999999999999
     START WITH 1
     INCREMENT BY 1
     CACHE 20;
    
Iswanto San
  • 18,263
  • 13
  • 58
  • 79
  • 3
    This also clobbers any grants on the sequence. – jim mcnamara Feb 06 '13 at 03:57
  • 2
    But dropping of a sequence invalidates all objects associated with the sequence and they all need to be recompiled. Any privileges will also be revoked and need to be granted again to the tasks associated with the newly created sequence. – Tiny Feb 06 '13 at 04:06