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: User Sequence Numbers

Re: User Sequence Numbers

From: Matthias Rogel <rogelREMOVE_at_THISweb.de>
Date: Fri, 31 Jan 2003 10:52:14 +0100
Message-ID: <b1dh0e$1291bl$1@ID-86071.news.dfncis.de>


Hermann Angstl wrote:
> Hi,
>
> let's create the following table:
>
> create table foo (k number(5)); -- dont add primary key on k --
> insert into foo values (1);
> insert into foo values (2);
> insert into foo values (3);
> commit;
>
> Is it possible, with the following statement, to create unique numbers ?
> Even with multiple sessions ?
>
> select k from foo where k in (select max(k) from foo) for update of k;
> k++;
> insert into foo values (new_k);
> commit;
>

no.
you don't want to update, so you don't need to lock a row

> ... is there another solution ?
>

lock table foo in exclusive mode;
insert into foo select nvl(max(k) + 1, 1) from foo; commit;

this solution is not so good (suppose you are not the only one wanting to do that, you have to lock the whole table)

Oracle noticed that disadvantage and invented sequences.

have a look at them !!

matthias

> cu,
> hal
>
Received on Fri Jan 31 2003 - 03:52:14 CST

Original text of this message

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