Generating Random numbers query [message #609634] |
Mon, 10 March 2014 10:46 |
sspn2010
Messages: 167 Registered: October 2008
|
Senior Member |
|
|
Hi,
I've below table with the numbers from 10,000,000 to 99,999,999. Now i need to generate random numbers from this table based on the input.
create table TMP_SERIAL_NBR
(
serial_nbr NUMBER
);
INsert /*+ append parallel(a,16) */ into tmp_serial_nbr a
SELECT column_value as serial_nbr FROM TABLE(rowgen(10000000,99999999));
create or replace type numtab_type as table of number;
CREATE OR REPLACE FUNCTION rowgen(p_start_num in number, p_end_num IN NUMBER)
RETURN numtab_type DETERMINISTIC PIPELINED PARALLEL_ENABLE
AS
BEGIN
-- create or replace type numtab_type as table of number;
FOR i IN p_start_num..p_end_num
LOOP
PIPE ROW(i);
END LOOP;
RETURN;
END rowgen;
I need 40MM random numbers from tmp_serial_nbr and using below code to get random numbers. But this query is running for nearly 25 - 30 minues. Can someone help on how to tune this query to make it efficient?
create table final_random_nbr nologging as
SELECT ROWNUM AS SEQ_NBR, SERIAL_NBR
FROM ( SELECT SERIAL_NBR
FROM (SELECT /*+ parallel (tsn 16) */
SERIAL_NBR,
TRUNC (DBMS_RANDOM.VALUE (1, 999999999))
AS SORT_RNK
FROM TMP_SERIAL_NBR TSN)
ORDER BY SORT_RNK)
WHERE ROWNUM <= 40000000
Appreciate your help!
Thanks
SS
|
|
|
|
|
|
|