Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: temporarily stop and then restart autonumbering of primary key field

Re: temporarily stop and then restart autonumbering of primary key field

From: Billy <vslabs_at_onwe.co.za>
Date: 17 Aug 2005 23:38:17 -0700
Message-ID: <1124347097.507811.269490@z14g2000cwz.googlegroups.com>


brightspot wrote:

> My table has a primary key field with the values 1 through 5 in it. I
> want to suspend autonumbering, set the next value to 38, resume
> autonumbering and have Oracle continue on with value 39. The column
> would look like this:
> 1
> 2
> 3
> 4
> 5
> 38
> 39
> 40
> ...
>
> Is this possible using PL/SQL from a stored procedure?

Yes. Simply fast forward the sequence. Something like this:

loop

   select seqname.nextval into i from dual;    exit when i >= 37;
end loop;

Re-creating the sequence is not such a good idea as it will break (invalidate) existing code using that sequence, there are potential issues of grants and so on. All solvable problems - but I will rather simply fast forward like above as it will have no impact on existing running software, whereas dropping and re-create an object does.

--
Billy
Received on Thu Aug 18 2005 - 01:38:17 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US