现在的位置: 首页 > 综合 > 正文

oracle 产生随机数,取整

2013年09月12日 ⁄ 综合 ⁄ 共 311字 ⁄ 字号 评论关闭

oracle 里的 dbms_random.value 产生的是一个带有小数部分的数,当给它限定范围,并且想要得到一个整数的时候就应该:

floor(dbms_random.value*200+1);

 

select   floor(12.23)   from   dual;  
   
  FLOOR(12.23)  
  ------------  
  12  

 

select   round(2.34)   from   dual;  
  2

  select   round(2.34,0)   from   dual;  
  2  

 

round()是四舍五入,不是取整 
ceil()是进一,floor()是去尾,都是返回整数
trunc()也是去尾,但是可以指定小数位数,不指定即为取整

 

抱歉!评论已关闭.