您的位置:首页 > 数据库 > Oracle

oracle限定返回结果集的行数

2013-10-11 20:26 281 查看
在mysql中,可以通过limit限制返回结果集的行数,如:

select * from user_table limit 2;


返回了user_table的前两行,在oracle中没有limit,如果oracle要得到同样的结果,则:

select * from user_table where rownum < 3;


这里rownum是内置关键字,表示结果集的行号,但是不能对rownum进行复合条件判断,如果要返回第11行至第20行10条数据,不能这样写:

select * from user_table where rownum > 10 and rownum < 21;


而是应该写成结果集相减的形式:

select * from user_table where rownum < 21
minus
select * from user_table where rownum < 11;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: