ITPub博客

首页 > 数据库 > Oracle > 产生任意的随机三条数据

产生任意的随机三条数据

原创 Oracle 作者:Angelina7 时间:2016-11-17 13:45:53 0 删除 编辑


order  by dbms_random.value(1,50),再嵌套一层rownum




select *
  from (select rownum, empno
          from (select empno from emp order by dbms_random.value(1, 50)))
 where rownum <= 3;


测试结果:
SQL> select *
  2    from (select rownum, empno
  3            from (select empno from emp order by dbms_random.value(1, 50)))
  4   where rownum <= 3;
    ROWNUM EMPNO
---------- -----
         1  7654
         2  7902
         3  7499


SQL> 
SQL> select *
  2    from (select rownum, empno
  3            from (select empno from emp order by dbms_random.value(1, 50)))
  4   where rownum <= 3;
    ROWNUM EMPNO
---------- -----
         1  7902
         2  7900
         3  7654

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31402276/viewspace-2128618/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2016-10-14

  • 博文量
    31
  • 访问量
    12512