Search code examples
oracle-databaseplsql

Create a PLSQL sequence which gives random values?


My question is about PL SQL sequence which need to give random values between start with value and max value. Can we able to do this?


Solution

  • Sure, use DBMS_RANDOM.VALUE. Here is a brief proof of concept:

    set serveroutput on
    
    declare
      x number;
    begin
      x := dbms_random.value(3, 9);
      dbms_output.put_line(x);
    end;
    /
    
    7.77738390408807611656323701045019115674
    
    
    PL/SQL procedure successfully completed.
    

    You may want to take a look at the whole package: https://docs.oracle.com/database/121/ARPLS/d_random.htm#ARPLS040