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;

Tags:

Oracle

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Search

Calendar

«  May 2012  »
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Recent comments

Archive