从SQLSERVER与ORACLE数据库中随机取记录

从SQLSERVER与ORACLE数据库中随机取记录

在sql server中,从数据表中随机取出n条记录,使用以下SQL语句:

select   top  n  *   from  tableName  order   by   newid ()

在oralce中,从数据表中随机取出n条记录,使用以下SQL语句

select     *     from    ( select    tableName . * ,dbms_random.random  as randomKey    from  tableName   order    by    randomKey)    
  
where    rownum <= n


Let life be beautiful like summer flowers and death like autumn leaves.

你可能感兴趣的:(从SQLSERVER与ORACLE数据库中随机取记录)