oracle dbms_random.value,dbms_random.value

來源:互聯網
上載者:User

oracle dbms_random.value,dbms_random.value

dbms_random是一個可以產生隨機數值或者字串的程式包。包中value()的用法有兩種
第一種無參,會返回一個具有38位精度的數值,範圍從0.0到1.0,但不包括1.0:
第二種value帶有兩個參數,第一個指下限,第二個指上限,將會產生下限到上限之間的數字,不包含上限:
例1:無參用法、輸出1到99之間的隨意10個數

<span style="font-size:18px;">SQL> set serverout on SQL> begin    2    for i in 1..10 loop    3      dbms_output.put_line(round(dbms_random.value*100));    4    end loop;    5  end;    6  / </span>


 
例2:有參用法、輸出1到100之間的任意10個數

<span style="font-size:18px;">SQL> begin    2    for i in 1..10 loop    3      dbms_output.put_line(trunc(dbms_random.value(1,101)));    4    end loop;    5  end;    6  / </span>



 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.