PLSQL generate random integer

后端 未结 6 1175
离开以前
离开以前 2021-02-08 11:53

In Oracle Sql developer 11g, how do I generate a random integer and assign it to a variable? This is what I\'ve tried so far:

S_TB := SELECT dbms_random.value(1,         


        
6条回答
  •  一生所求
    2021-02-08 12:37

    Alternatively, You can create a function for generating random numbers. This can be used in anywhere in the code.

        create or replace function RANDOM
        return number 
        is 
        a number ; 
        begin
        select round(dbms_random.value(1,10)) rnum
        into a 
        from dual;
        return a  ;
        end;
        /
    

    OUTPUT:

    Function created.

    SQL> select Random from dual;

    RANDOM

         6                                                                                                                  
    

    SQL> select Random from dual;

    RANDOM

         9                                                                                                                  
    

提交回复
热议问题