7.10 DBMS_RANDOM

Table of Contents Previous Next


7 Built-In Packages : 7.10 DBMS_RANDOM

The DBMS_RANDOM package provides a number of methods to generate random values. The procedures and functions available in the DBMS_RANDOM package are listed in the following table.
Initializes the DBMS_RANDOM package with the specified seed value. Deprecated, but supported for backward compatibility.
Returns a random INTEGER with a value greater than or equal to -2^31 and less than 2^31. Deprecated, but supported for backward compatibility.
SEED(val)
SEED(val)
STRING(opt, len)
TERMINATE has no effect. Deprecated, but supported for backward compatibility.
Returns a random number with a value greater than or equal to 0 and less than 1, with 38 digit precision.
VALUE(low, high)
7.10.1 INITIALIZE
The INITIALIZE procedure initializes the DBMS_RANDOM package with a seed value. The signature is:
INITIALIZE(val IN INTEGER)
val is the seed value used by the DBMS_RANDOM package algorithm.
The following code snippet demonstrates a call to the INITIALIZE procedure that initializes the DBMS_RANDOM package with the seed value, 6475.
7.10.2 NORMAL
The NORMAL function returns a random number of type NUMBER. The signature is:
result NUMBER NORMAL()
result is a random value of type NUMBER.
7.10.3 RANDOM
The RANDOM function returns a random INTEGER value that is greater than or equal to -2 ^31 and less than 2 ^31. The signature is:
result INTEGER RANDOM()
result is a random value of type INTEGER.
The following code snippet demonstrates a call to the RANDOM function. The call returns a random number:
7.10.4 SEED
The first form of the SEED procedure resets the seed value for the DBMS_RANDOM package with an INTEGER value. The SEED procedure is available in two forms; the signature of the first form is:
SEED(val IN INTEGER)
val is the seed value used by the DBMS_RANDOM package algorithm.
The following code snippet demonstrates a call to the SEED procedure; the call sets the seed value at 8495.
7.10.5 SEED
The second form of the SEED procedure resets the seed value for the DBMS_RANDOM package with a string value. The SEED procedure is available in two forms; the signature of the second form is:
SEED(val IN VARCHAR2)
val is the seed value used by the DBMS_RANDOM package algorithm.
The following code snippet demonstrates a call to the SEED procedure; the call sets the seed value to abc123.
7.10.6 STRING
The STRING function returns a random VARCHAR2 string in a user-specified format. The signature of the STRING function is:
result VARCHAR2 STRING(opt IN CHAR, len IN NUMBER)
u or U
l or L
a or A
x or X
p or P
result is a random value of type VARCHAR2.
The following code snippet demonstrates a call to the STRING function; the call returns a random alpha-numeric character string that is 10 characters long.
7.10.7 TERMINATE
The TERMINATE procedure has no effect. The signature is:
The TERMINATE procedure should be considered deprecated; the procedure is supported for compatibility only.
7.10.8 VALUE
The VALUE function returns a random NUMBER that is greater than or equal to 0, and less than 1, with 38 digit precision. The VALUE function has two forms; the signature of the first form is:
result NUMBER VALUE()
result is a random value of type NUMBER.
The following code snippet demonstrates a call to the VALUE function. The call returns a random NUMBER:
7.10.9 VALUE
The VALUE function returns a random NUMBER with a value that is between user-specified boundaries. The VALUE function has two forms; the signature of the second form is:
result NUMBER VALUE(low IN NUMBER, high IN NUMBER)
low specifies the lower boundary for the random value. The random value may be equal to low.
high specifies the upper boundary for the random value; the random value will be less than high.
result is a random value of type NUMBER.
The following code snippet demonstrates a call to the VALUE function. The call returns a random NUMBER with a value that is greater than or equal to 1 and less than 100:

7 Built-In Packages : 7.10 DBMS_RANDOM

Table of Contents Previous Next