首页 > 数据库

oracle数据库实现分页查询

时间:2009-04-16 20:21:28  作者:云之巅  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
如从表中取出4-6行的数据;sql如下:得到4-6行的数据select id,agefrom zystudentwhere id in(select id from zystudentwhere rownum<=6 and id not in(select id......

如从表中取出4-6行的数据;

sql如下:

得到4-6行的数据
select id,age
from zystudent
where id in(
select id
from zystudent
where rownum<=6
and
id not in(
select id from zystudent where rownum<=3)
);

最笨的方法,查询效率很低,不建议使用

select id,name,age from(
select id,name,age,rownum r
from zystudent) where r>=3 and r<=6;

将rownum定义成一个属性,然后调用,很不错的方法

select id,name,age from(
select id,name,age,rownum r
from zystudent where rownum<=6 order by id) where r>=4;

比上一个,更加优化了查询,根本不用遍历全表,就能实现

排序后再取出4-6;
select id,name,age from(
select id,name,age,rownum r
from(select * from zystudent order by id desc) where rownum<=6) where r>=4;

应该将排序的后的表作为要查询的表

如果您需转载 oracle数据库实现分页查询,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门