| René Nyffenegger's collection of things on the web | |
|
René Nyffenegger on Oracle - Most wanted - Feedback
|
dbms_random | ||||||||||||
|
dbms_random allows to generate random data. With 10g, there are three
random generators in dbms_crypto that produce better random values than
dbms_random.
Initialize(val in binary_integer)
Initialize is obsolete. It calls the procedure seed.
Normal
Returns a random number from a normal distribution.
Seed
Seed is an overloaded procedure with one parameter that either takes a binary_integer or a varchar2.
By default, the pakcage is Initialized (seeded) with the current user name, the time (accurate downt to the second) and the current session
PackStringdbms_random.string(opt, len);
The function string returns a string whose length is determined by the len argument.
The returned string's characteristics are determined by the opt argument. opt must be a
char. The following five
options are possible:
col u format a10 col l format a10 col a format a10 col x format a10 col p format a10 select dbms_random.string('u', 10) u, dbms_random.string('l', 10) l, dbms_random.string('a', 10) a, dbms_random.string('x', 10) x, dbms_random.string('p', 10) p from dual; U L A X P ---------- ---------- ---------- ---------- ---------- QRBBMHKILH eyotdrlvms DQQqXImnXt ONU82BQHZS `TKzRQ$[sR Valuedbms_random.value(); dbms_random.value(low, high);
The function value comes in two specifications:
dbms_random.value() and dbms_random.value(low in number, high in number).
If called without parameters, it will return a (pseudo random) number between 0 and 1. This range can be extended to return a (pseudo random)
number between a freely choosable lower limit (low) and higher limit(high).
begin for i in 1 .. 20 loop dbms_output.put_line ( i || ': ' || dbms_random.value(0, 10) ); end loop; end; / Terminate
The procedure terminate is obsolete and does nothing (at least in Oracle 9).
Examples
dbms_random is used in my dummy data generator.
|