Be alaways javaing...

Loving Java
posts - 43, comments - 5, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

表中随机返回n条记录

Posted on 2008-07-03 23:08 追风舞者 阅读(145) 评论(0)  编辑  收藏 所属分类: Database
1.MySQL
    同时使用内置RAND函数、LIMIT函数和ORDER BY
        select * from table
            order by rand()  limit 5
2.Oracle
    同时使用DBMS_RANDOM包中的内置函数 VALUE、 ORDER BY和内置函数ROWNUM
       select * from(
           select name from table order by dbms_random.value()
        ) where rownum <=5

只有注册用户登录后才能发表评论。


网站导航: