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

Home -> Community -> Usenet -> c.d.o.server -> Re: how to generate a randomized "seqno" column

Re: how to generate a randomized "seqno" column

From: DA Morgan <damorgan_at_psoug.org>
Date: Thu, 19 Oct 2006 08:58:36 -0700
Message-ID: <1161273511.329568@bubbleator.drizzle.com>


Cris wrote:
> I have to write a pl/sql stored procedure that generates n rows
> identified by a progressive ID and with another column that gives the
> rows a unique, random seqno.
>
> E.g.:
>
> ID SEQNO
> -- -----
> 1 3
> 2 6
> 3 1
> 4 2
> 5 5
> 6 4
>
> The first silly idea that comes to my mind is to loop from 1 to n and,
> inside the loop, to call repeatedly dbms_crypto.randomInteger until he's
> able to find a new unique seqno.
>
> This looks to me like a performance killer. Are there more intelligent
> alternatives?
>
> Thank you. Kind regards,

And your Oracle version is?/

In 10g use DBMS_CRYPTO.RANDOMINTEGER or DBMS_CRYPTO.RANDOMNUMBER.

In previous versions use the DBMS_RANDOM built-in.

Demos of all can be found in Morgan's Library at www.psoug.org.

-- 
Daniel A. Morgan
University of Washington
damorgan_at_x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Received on Thu Oct 19 2006 - 10:58:36 CDT

Original text of this message

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