PLSQL generate random integer

后端 未结 6 1172
离开以前
离开以前 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:44

    If you want to get a random number of n digits you can do this

    CREATE OR REPLACE FUNCTION NUM_RANDOM(N IN NUMBER)
    RETURN NUMBER 
    AS 
    BEGIN
        RETURN TRUNC (DBMS_RANDOM.VALUE(POWER(10, N - 1), POWER(10, N) - 1));
    END NUM_RANDOM;
    

提交回复
热议问题