ORACLE (dbms_random)随机数

 
declare 
  -- Local variables here
  num integer;
  seed number:=1000000;
  
  a number(10);--隨機數
  b number(10);--一百以內的隨機數
  c number(10);--100到1000的隨機數
  d number(10);--0到1的隨機數
  e number(10);--1到199的隨機數
  f number(10);--1到199的隨機整數
  g varchar2(20);--隨機字符
  h number(10);--正態分佈的隨機數
  k varchar2(38);--隨機數字字符串
  i date;--隨機日期
  guid varchar2(38);
 
begin
  -- Test statements here
  dbms_random.initialize(seed);
  dbms_output.put('seed:'||seed);
  dbms_output.new_line;
 /** 
  for i in 1..10 loop
      num:=dbms_random.random()/seed;  
        dbms_output.put_line('num:'||num);
        
     -- dbms_random.seed(seed);
        dbms_output.put('seed:'||seed);
        dbms_output.new_line;
  end loop;
  **/
  
  select dbms_random.random into a  from dual;--隨機數
  select abs(mod(dbms_random.random,100)) into b  from dual;--一百以內的隨機數
  select trunc(dbms_random.value*900+100) into c  from dual;--100到1000的隨機數
  select dbms_random.value into d  from dual;--0到1的隨機數
  select dbms_random.value(1,199) into e  from dual;--1到199的隨機數
  select trunc(dbms_random.value(1,199)) into f  from dual;--1到199的隨機整數
  select dbms_random.string('p',10) into g  from dual;--隨機字符--p:可打印,u:大寫,l:小寫,a:大小寫,x:數字和大寫字母
  select dbms_random.normal into h  from dual;--正態分佈的隨機數
  select to_date(2454084+TRUNC(DBMS_RANDOM.VALUE(0,365)),'J') into i  from dual;--隨機日期
  select substr(cast(dbms_random.value as varchar2(38)),3,20) into k from dual;--隨機數字字符串
  select sys_guid() into guid from dual;
  
  dbms_output.put_line(a||'+'||b||'+'||c||'+'||d||'+'||e||'+'||f||'+'||g||'+'||h||'+'||i||'+'||k||'+'||guid);
  
  dbms_random.terminate;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不知道叫什麽名字

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值