DBMS_RANDOM v15
The DBMS_RANDOM
package provides methods to generate random values. The procedures and functions available in the DBMS_RANDOM
package are listed in the following table.
Function/procedure | Return type | Description |
---|---|---|
INITIALIZE(val) | n/a | Initializes the DBMS_RANDOM package with the specified seed value . Deprecated, but supported for backward compatibility. |
NORMAL() | NUMBER | Returns a random NUMBER . |
RANDOM | INTEGER | 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) | n/a | Resets the seed with the specified value . |
SEED(val) | n/a | Resets the seed with the specified value . |
STRING(opt, len) | VARCHAR2 | Returns a random string. |
TERMINATE | n/a | TERMINATE has no effect. Deprecated, but supported for backward compatibility. |
VALUE | NUMBER | Returns a random number with a value greater than or equal to 0 and less than 1 , with 38-digit precision. |
VALUE(low, high) | NUMBER | Returns a random number with a value greater than or equal to low and less than high . |
INITIALIZE
The INITIALIZE
procedure initializes the DBMS_RANDOM
package with a seed value. The signature is:
This procedure is deprecated. It is included for backward compatibility.
Parameters
val
val
is the seed value used by the DBMS_RANDOM
package algorithm.
Example
The following code shows a call to the INITIALIZE
procedure that initializes the DBMS_RANDOM
package with the seed value 6475:
NORMAL
The NORMAL
function returns a random number of type NUMBER
. The signature is:
Parameters
result
result
is a random value of type NUMBER
.
Example
The following code shows a call to the NORMAL
function:
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:
This function is deprecated. It is included for backward compatibility.
Parameters
result
result
is a random value of type INTEGER
.
Example
The following code shows a call to the RANDOM
function. The call returns a random number:
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:
Parameters
val
val
is the seed value used by the DBMS_RANDOM
package algorithm.
Example
The following code shows a call to the SEED
procedure. The call sets the seed value at 8495.
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:
Parameters
val
val
is the seed value used by the DBMS_RANDOM
package algorithm.
Example
The following code shows a call to the SEED
procedure. The call sets the seed value to abc123
.
STRING
The STRING
function returns a random VARCHAR2
string in a user-specified format. The signature of the STRING
function is:
Parameters
opt
Formatting option for the returned string. option
can be:
Option | Specifies formatting option |
---|---|
u or U | Uppercase alpha string |
l or L | Lowercase alpha string |
a or A | Mixed-case string |
x or X | Uppercase alphanumeric string |
p or P | Any printable characters |
len
The length of the returned string.
result
result
is a random value of type VARCHAR2
.
Example
The following code shows a call to the STRING
function. The call returns a random alphanumeric character string that is 10 characters long.
TERMINATE
The TERMINATE
procedure has no effect. The signature is:
The TERMINATE
procedure is deprecated. The procedure is supported for compatibility.
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:
Parameters
result
result
is a random value of type NUMBER
.
Example
The following code shows a call to the VALUE
function. The call returns a random NUMBER
:
VALUE
The VALUE
function returns a random NUMBER
with a value that is between boundaries that you specify. The VALUE
function has two forms. The signature of the second form is:
Parameters
low
low
specifies the lower boundary for the random value. The random value can be equal to low
.
high
high
specifies the upper boundary for the random value. The random value is less than high
.
result
result
is a random value of type NUMBER
.
Example
The following code shows 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: