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

Oracle分页

2017-02-26 22:14 120 查看
如果我们都这样写分页:

select t.*
from(
select fieldName,rownum rn
from tableName t
where t.fieldName = condition
and rownum <= a
) t
where rn > b


或者这样:

select t.*
from(
select fieldName,rownum rn
from tableName t
where t.fieldName = condition
) t
where rn <= a and rn > b


那就要注意了,这样的写法有可能会出现重复项。

正确的写法:

select fieldName...
from(
select n.*,ruwnum
from(
select t.*
from tableName t
where t.fieldName=condition
order by primaryKey
)n where rownum<=end)
where rn>=start
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle