oracle分页 语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle分页 语句相关的知识,希望对你有一定的参考价值。
String sql = "select * from student where rowCount> "+currentPage*(pageSize-1)+" and rowCount<= "+currentPage*pageSize+"";
请问这句什么意思啊 这是在java里面
currentPage*(pageSize-1) 这句什么意思啊 是不是他写错了 (currentPage-1)*pageSize应该是这样吧
select /*+first_rows(10)*/ b.* from
(select /*+first_rows(10)*/ a.*,rownum rnum from
(select /*+first_rows(10)*/ * from student ) a where rownum<= "+currentPage*pageSize+"
)b
where rnum>= (currentPage-1)*pageSize;
这个意思就是认为的在sql中添加hint 数据库返回指定条目的数据是最快的。 参考技术A 1.oracle数据库分页
select * from (select a.*,rownum rc from 表名 where rownum<=endrow) a where a.rc>=startrow
2.DB2数据库分页
Select * from (select rownumber() over() as rc,a.* from (select * from 表名 order by 列名) as a) where rc between startrow and endrow
3.SQL Server 2000数据库分页
Select top pagesize * from 表名 where 列名 not in(select top pagesize*page 列名 from 表名 order by 列名) order by 列名
4.SQL Server 2005数据库分页
Select * from (select 列名,row_number() over(order by 列名1) as 别名from 表名) as t where t.列名1>=startrow and t.列名1<=endrow
5.MySQL数据库分页
Select * from 表名 limit startrow,pagesize
(Pagesize为每页显示的记录条数)
6.PostgreSQL数据库分页
Select * from 表名 limit pagesize,offset startrow
(Pagesize为每页显示的记录条数.) 参考技术B currentPage是每页显示多少条.
pageSize是要显示第几页 参考技术C 下面两种用可以用rownum的变通方式实现分页:nbsp;selectnbsp;*nbsp;fromnbsp;(selectnbsp;rownumnbsp;row_num,month,sellnbsp;fromnbsp;(selectnbsp;month,sellnbsp;fromnbsp;salenbsp;groupnbsp;bynbsp;month,sell)nbsp;)nbsp;wherenbsp;row_numnbsp;betweennbsp;5nbsp;andnbsp;9;【网友评论】nbsp;selectnbsp;dmp.row_num,dmp.requirement_idnbsp;fromnbsp;(selectnbsp;rownumnbsp;asnbsp;row_num,nbsp;requirement_idnbsp;fromnbsp;(selectnbsp;requirement_idnbsp;fromnbsp;requirementnbsp;ordernbsp;bynbsp;requirement_idnbsp;desc)nbsp;)nbsp;dmpnbsp;wherenbsp;row_numnbsp;betweennbsp;10nbsp;andnbsp;20;
常用sql 分页语句(Oracle)
常用的Oracle查询语句
1.无ORDER BY排序的写法。(效率最高)
经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!
sql语句如下:
SELECT *
FROM (Select ROWNUM AS ROWNO, T.*
from k_task T
where Flight_date between to_date(‘20060501‘, ‘yyyymmdd‘) and
to_date(‘20060731‘, ‘yyyymmdd‘)
AND ROWNUM <= 20) TABLE_ALIAS
WHERE TABLE_ALIAS.ROWNO >= 10;
2.有ORDER BY排序的写法。(效率最高)
经过测试,此方法随着查询范围的扩大,速度也会越来越慢!
SELECT *
FROM (SELECT TT.*, ROWNUM AS ROWNO
FROM (Select t.*
from k_task T
where flight_date between to_date(‘20060501‘, ‘yyyymmdd‘) and
to_date(‘20060531‘, ‘yyyymmdd‘)
ORDER BY FACT_UP_TIME, flight_no) TT
WHERE ROWNUM <= 20) TABLE_ALIAS
where TABLE_ALIAS.rowno >= 10;
3.无ORDER BY排序的写法。(建议使用方法1代替)
此方法随着查询数据量的扩张,速度会越来越慢!
SELECT *
FROM (Select ROWNUM AS ROWNO, T.*
from k_task T
where Flight_date between to_date(‘20060501‘, ‘yyyymmdd‘) and
to_date(‘20060731‘, ‘yyyymmdd‘)) TABLE_ALIAS
WHERE TABLE_ALIAS.ROWNO <= 20
AND TABLE_ALIAS.ROWNO >= 10;
TABLE_ALIAS.ROWNO between 10 and 100;
4.有ORDER BY排序的写法.(建议使用方法2代替)
此方法随着查询范围的扩大,速度也会越来越慢!
SELECT *
FROM (SELECT TT.*, ROWNUM AS ROWNO
FROM (Select *
from k_task T
where flight_date between to_date(‘20060501‘, ‘yyyymmdd‘) and
to_date(‘20060531‘, ‘yyyymmdd‘)
ORDER BY FACT_UP_TIME, flight_no) TT) TABLE_ALIAS
where TABLE_ALIAS.rowno BETWEEN 10 AND 20;
5.另类语法。(有ORDER BY写法)
该语法风格与传统的SQL语法不同,不方便阅读与理解,为规范与统一标准,不推荐使用。此处贴出代码供大家参考之用。
With partdata as(
SELECT ROWNUM AS ROWNO, TT.* FROM (Select *
from k_task T
where flight_date between to_date(‘20060501‘, ‘yyyymmdd‘) and
to_date(‘20060531‘, ‘yyyymmdd‘)
ORDER BY FACT_UP_TIME, flight_no) TT
WHERE ROWNUM <= 20)
Select * from partdata where rowno >= 10;
6.另类语法 。(无ORDER BY写法)
With partdata as(
Select ROWNUM AS ROWNO, T.*
From K_task T
where Flight_date between to_date(‘20060501‘, ‘yyyymmdd‘) and
To_date(‘20060531‘, ‘yyyymmdd‘)
AND ROWNUM <= 20)
Select * from partdata where Rowno >= 10;
以上是关于oracle分页 语句的主要内容,如果未能解决你的问题,请参考以下文章