dbms_random package [message #15436] |
Thu, 07 October 2004 21:25  |
dhananjay
Messages: 635 Registered: March 2002 Location: Mumbai
|
Senior Member |
|
|
hi,
i m trying to populate a table using dbms_random,but i m getting an error 'invalid column'.i have gone thru the doc ,but couldn't figure out what it meant.Do i need to run some script ?can someone help me .i m using 8.1.5.
regards
|
|
|
|
|
|
Re: dbms_random package [message #15631 is a reply to message #15447] |
Sun, 17 October 2004 21:36   |
dhananjay
Messages: 635 Registered: March 2002 Location: Mumbai
|
Senior Member |
|
|
hi,
sorry to revert back late.
but, when i try to describe dbms_random, i get the following err.
object dbms_random does not exist
ORA-04043:
do, i need to run some script ?
plz explain.
regards,
|
|
|
Re: dbms_random package [message #15662 is a reply to message #15631] |
Mon, 18 October 2004 14:49  |
 |
Barbara Boehmer
Messages: 9106 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
On newer versions of Oracle, there is no need to run a script to install the dbms_random package, but on Oracle 8.1.5 you have to install the dbms_random package by either finding and running your catoctk.sql file or by running both the prvtoctk.plb and dbmsoctk.sql files. You must be connected as sys when you run the script(s). However, you still will not have the string function, since that was introduced in 9i. You could write something to convert a number of randomly generated numbers to a string of characters, using chr() or some such thing to convert the numbers to characters, being careful to use only those numeric values, where the chr() of the value is a letter. Please see the example below.
scott@ORA92> CREATE OR REPLACE FUNCTION my_random_string
2 (p_length IN NUMBER)
3 RETURN VARCHAR2
4 AS
5 v_string VARCHAR2(32767);
6 v_num NUMBER;
7 BEGIN
8 FOR i IN 1 .. p_length LOOP
9 SELECT MOD (ABS (DBMS_RANDOM.RANDOM), 25) INTO v_num FROM DUAL;
10 v_num := v_num + 65;
11 v_string := v_string || CHR (v_num);
12 END LOOP;
13 RETURN v_string;
14 END my_random_string;
15 /
Function created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> SELECT my_random_string (5) FROM DUAL
2 /
MY_RANDOM_STRING(5)
----------------------------------------------------------------------------------------------------
LCNPF
scott@ORA92> SELECT my_random_string (5) FROM DUAL
2 /
MY_RANDOM_STRING(5)
----------------------------------------------------------------------------------------------------
TMTCI
scott@ORA92> SELECT my_random_string (5) FROM DUAL
2 /
MY_RANDOM_STRING(5)
----------------------------------------------------------------------------------------------------
ASYSX
|
|
|