Setting a sequence's next value in Oracle

by timvasil 11/20/2008 12:10:00 PM

You can't set the next value of a sequence directly in Oracle; you have to drop and recreate the sequence.  Here's a way to do it if you need to set the next value to the largest value in a particular column plus 1:

declare
    nextId number;
begin
    select coalesce(max(PrimaryID), 0) + 1 into nextId from Table;
    execute immediate 'drop sequence PrimaryIDSeq';
    execute immediate 'create sequence PrimaryIDSeq minvalue ' || nextId;
end;

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Oracle

Related posts

Comments are closed

 

About the author

Tim Vasil Tim Vasil
I'm a software engineer living in Cambridge, MA.

E-mail me Send mail

Search

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Recent comments