I need to create a table with random values from another table. For that, I tried using a LOOP
that collects random FIRST_NAME
and LAST_NAME
from the other table and puts them in my table.
But using a LOOP does not work as the SELECT
statement does not execute more than once.
BEGIN
LOOP
v_counter:=v_counter+1;
SELECT fname INTO v_fname FROM users SAMPLE (5) WHERE some_condition AND ROWNUM=1;
SELECT lname INTO v_lname FROM users SAMPLE (5) WHERE some_condition AND ROWNUM=1;
DBMS_OUTPUT.PUT_LINE(v_fname2);
EXIT WHEN (v_counter > 50);
END LOOP;
END;
I get the same name printed 50 times.