Section A.5. DBMS_RANDOM


A.5. DBMS_RANDOM

This package contains programs that generate random values (numbers or strings) and perform other randomization operations.

SEED

This program initializes the DBMS_RANDOM package with a user-specified "seed" that will be used to generate random values. Having a different seed value for different programs ensures the generation of sufficiently random values. SEED is overloaded: both versions are functions, each accepting a parameter of a different datatype.

FunctionVersion 1

Accepts a single parameter, val, which will be used as the seed value. The parameter is a VARCHAR2 value, which may be up to 2,000 bytes.

FunctionVersion 2

Accepts a single parameter, val, which will be used as the seed value. The parameter is a BINARY_INTEGER value.

VALUE

This program returns a random number: a positive, floating-point number less than one. VALUE is overloaded: both versions are functions, one with parameters and one without.

FunctionVersion 1 (no parameters)

Returns a random number in the NUMBER datatype. There are no parameters.

FunctionVersion 2 (parameters)

Returns a random number in the NUMBER datatype. This version accepts two input parameters: low and high. The returned value will be between the low and high values.

Parameter name

Datatype

Description

low

NUMBER

Lower-bound for the returned random number

high

NUMBER

Upper-bound for the returned random number


STRING

This function returns a random string. This string is of a user-specified length and distribution of characters. It accepts two input parameters.

Parameter name

Datatype

Description

opt

VARCHAR2

Option specifying the random string to be generated (see the following table for options)

len

NUMBER

Length of random string to be generated


The opt parameter may have any of the values shown in the following table.

opt value

Effect

u

Generates uppercase alphabets only (e.g., DFTHNDSW)

l

Generates lowercase alphabets only (e.g., pikdcdsd)

a

Generates mixed-case alphabets (e.g., DeCWCass)

x

Generates a mixture of uppercase alphabets and numbers (e.g., A1W56RTY)

p

Generates any printable characters (e.g., $\$2sw&*)


NORMAL

This function, like the VALUE function, returns a random number. However, the pattern of random number generation for NORMAL follows a normal distribution. That means that if you execute this function several times in succession, the generated numbers will follow a random number distribution. The NORMAL function has no input parameters.




Oracle PL(s)SQL For DBAs
Oracle PL(s)SQL For DBAs
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 122

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net