当前位置:首页 > 数据库 > Oracle

Oracle如何实现从特定组合中随机读取值

create table test(loc varchar2(2 char)); Table created.

构造能随机读取元素的SQL语句

select case mod(abs(dbms_random.random),5)
       when 1 then 北京
       when 2 then 上海
       when 3 then 广州
       when 4 then 深圳
       else 武汉 end "LOC"
from dual;

大批量填充test表的loc字段

begin
  for i in 1..10 loop
     insert into test values(case mod(abs(dbms_random.random),5)
          when 1 then 北京
          when 2 then 上海
          when 3 then 广州
          when 4 then 深圳
          else 武汉 end );
  end loop; 
end;

最后生成的结果如下:

SQL> select * from test;

LOC
--------
武汉
广州
上海
北京
上海
武汉
北京
上海
武汉
深圳

10 rows selected.

 

Oracle如何实现从特定组合中随机读取值

标签:

本文系统来源:http://www.cnblogs.com/ivictor/p/4504786.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐