Oracle分页

来源:互联网 发布:网络漫画培训 编辑:程序博客网 时间:2024/05/01 18:47

如果我们都这样写分页:

select t.* from(select fieldName,rownum rn from tableName t where t.fieldName = conditionand rownum <= a) twhere 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.*,ruwnumfrom(select t.* from tableName twhere t.fieldName=conditionorder by primaryKey)n where rownum<=end)where rn>=start
0 0
原创粉丝点击