Oracle DBMS_RANDOM
-- Code to select random value in an array
-- using
-- DBMS_RANDOM.value(low, high)

DECLARE  
   TYPE     va_num IS VARRAY(10) OF NUMBER;
   v_num    va_num;
   v_idx    PLS_INTEGER;
BEGIN  
  v_num := va_num(1,2,3,5,7,11,13,17,19,23);
  v_idx := ROUND(DBMS_RANDOM.value(1,v_num.COUNT));
      
  DBMS_OUTPUT.PUT(' Array -> ');
  FOR idx IN v_num.FIRST..v_num.LAST LOOP
    IF idx < v_num.LAST THEN 
       DBMS_OUTPUT.PUT(' '||v_num(idx)||', ');
    ELSE
       DBMS_OUTPUT.PUT_LINE(' '||v_num(idx));
    END IF;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE(' Random Value -> ['||
    v_idx||'] -> '||v_num(v_idx));
END;
/
   Oracle DBMS_RANDOM Numeric Data Analysis
DBMS_RANDOM To generate - Random String (password)

Oracle registered trademark of Oracle Corporation.

Last Revised On: April 04, 2012

  1091