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 1 people

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

Tags:

Oracle

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

1/7/2009 7:27:05 AM

 

About the author

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

E-mail me Send mail

Search

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent comments