首页 » ORACLE 9i-23ai » oracle 取随机整数

oracle 取随机整数

oracle 取随机数,可以用dbms_random包,生成8位随机字符串是dbms_random.string(x,8),

取整数可以用ceil,floor,trunc,round等函数

如,

SELECT DBMS_RANDOM.RANDOM FROM DUAL;

产生一个任意大小的随机数

SELECT ABS(MOD(DBMS_RANDOM.RANDOM,100)) FROM DUAL;

产生一个100以内的随机数

SELECT TRUNC(100+900*dbms_random.value) FROM dual;

产生一个100~1000之间的随机数

SELECT dbms_random.value FROM dual;

产生一个0~1之间的随机数

SELECT dbms_random.value(10,20) FROM dual;

产生一个10~20之间的随机数

1.取整(进一法)
select ceil(100.501) value from dual

—-

101

2.取整(退一法)
select floor(100.501) value from dual

—–

100

3.取整(截取)
select trunc(100.501) value from dual

—–

100

4.取整(舍入)
select round(100.501),round(100.401) value from dual

———

101   100

打赏

目前这篇文章有4条评论(Rss)评论关闭。

  1. Chieko Kaza | #1
    2011-12-21 at 07:41

    Keep em coming… you all do such a great job at such Concepts… can’t tell you how much I, for one appreciate all you do!

  2. college scholarships | #2
    2011-01-04 at 15:58

    If you are open to having a guest blog poster please reply and let me know. I will provide you with unique content for your blog, thanks.

    • Mahalia | #3
      2011-06-23 at 04:02

      Thanks guys, I just about lost it lkoonig for this.

      • Carley | #4
        2011-11-11 at 19:06

        So true. Honetsy and everything recognized.