在mysql中的sql语句:select * from 表明 limit 0,10; 换成Oracle因该怎么写

如题所述

mysql中的sql语句

select * from 表名 limit 0,10;

表示取表中的前10条数据(从第1条开始,取10条)

换成Oracle,相应功能的语句为:

select * from 表名 where rownum <= 10 ;

如果取[5,10]条,则,oracle语句写法有两种:

(1)
select   *   from   table   where   rownum<=10 
minus
select   *   from   table   where   rownum<5 ;
(2) 
select * 
from ( select rownum r,a.* 
       from table a 
       where rownum<=10 ) 
where r>=5;
因为rownum不支持>=操作,所以,要先将rownum实例化。
经测试,第二种写法,比第一种写法的效率要高。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-30
现在常用的而且高效的就是这样写
select * from (select a.*,rownum rn from table a where rownum <= 10) where rn > 0
第2个回答  2010-08-30
select * from tablename t where t.rownum<10

如果是第10到20条记录可以用

select * from tablename t where t.rownum<20 minus select * from tablename t where t.rownum<10本回答被提问者采纳
第3个回答  2015-10-09
oracle 用rownum

select * from 表明 where rownum>=0 and rownum<=10