Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: dmbs_random AND Oracle
DBMS_RANDOM is created by the ?/rdbms/admin/dbmsrand.sql script (Oracle8 only).
This package contains programs: Initialize, Seed, Random, Terminate
For more random number generation options, the cryptographic toolkit
package
(DBMS_CRYPTO_TOOLKIT) should be used. The DBMS_CRYPTO_TOOLKIT package is
created by dbmsoctk.sql
SQL> exec dbms_random.initialize (2); begin dbms_random.initialize (2); end; * ERROR at line 1: ORA-06550: line 1, column 7: PLS-00201: identifier 'DBMS_RANDOM.INITIALIZE' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored SVRMGR> connect internal Connected. SVRMGR> @dbmsoctk.sql Statement processed. Statement processed. Statement processed. DROP PUBLIC SYNONYM dbms_crypto_toolkit * ORA-01432: public synonym to be dropped does not exist Statement processed. Statement processed. SVRMGR> @prvtoctk.plb Statement processed. Statement processed. Statement processed. SVRMGR> @dbmsrand.sql Statement processed. Statement processed. DROP PUBLIC SYNONYM dbms_random * ORA-01432: public synonym to be dropped does not exist Statement processed. Statement processed. 2. Initialize random number generator with seed. The seed should be at least 5 digits according to the package comments to ensure randomness. Example: SQL> exec dbms_random.initialize (12345); PL/SQL procedure successfully completed.
3. Generate random number.
Example 1:
SQL> set serveroutput on
SQL> declare 2 random_number binary_integer; 3 begin 4 random_number := dbms_random.random; 5 dbms_output.put_line(to_char(random_number)); 6 end; 7 / 2116177396 PL/SQL procedure successfully completed. Example 2: (from Oracle Cryptographic Toolkit Programmer's Guide Rel 2.0.4) DECLARE i BINARY_INTEGER; BEGIN dbms_random.initialize(19254); i := dbms_random.random; INSERT INTO some_table VALUES(i); dbms_random.terminate; END;
4. Terminate the random number generator to release memory.
Example:
SQL> exec dbms_random.terminate;
PL/SQL procedure successfully completed.
5. Change the random number generator seed after initial
initialization.
Example:
SQL> exec dbms_random.seed (12346);
PL/SQL procedure successfully completed.
6. Warnings
If dbms_random.terminate has been executed after dbms_random.random was successful, then subsequent executions of dbms_random.random may return neither a result or an error. If dbms_random.random is run before executing dbms_random.initialize then an exception will be raise and "ORA-06510: PL/SQL: unhandled user-defined exception results if the exception is not handled in the pl/sql block. It is not currently possible to use the return value of the random function directly in a SQL statement. Example: SQL> exec dbms_random.initialize (12345); PL/SQL procedure successfully completed. SQL> insert into x values(dbms_random.random); insert into x values(dbms_random.random) * ERROR at line 1: ORA-06571: Function RANDOM does not guarantee not to update the database.
I hope this is of any help
Regards
Yass Khogaly
Senior Principal Consultant Core Technology Services
Oracle Consulting
Oracle Corporation
"The Views expressed here are my own and not necessarily those of Oracle Corporation"
John Seitz <seitz_at_pobox.com> wrote in message
news:B3sk3.1257$YU3.15970_at_newse3.tampabay.rr.com...
> I have looked everywhere for DBMS_RANDOM packet. I have Personal Oracle
> 8.04 and Oracle Enterprise 8.05, and I can't find the package.
>
> I have queried the all_objects view looking for anything than contains
> RANDOM in its name. I have used Toad to browse all the procedure and
> packages in all the users. Nothing.
>
> Am I smoking the pipe, or am I missing something?
>
> John Seitz
>
>
>
Received on Sun Jul 18 1999 - 21:11:24 CDT
![]() |
![]() |