Oracle的分页:
Oracle 有rownum字段,rownum是一个伪列,是oracle系统自动为查询返回结果的每行分配的编号,第一行为1,第二行为2 ,以此类推。。。
有两种分页的方法:
第一种:利用rownum伪列方法
表名 ROL_TEMPLATE_FUNCTION 要求:搜索第21个到第40个的数据
select *
from (select rownum as rowno, A.*
from (SELECT * FROM ROL_TEMPLATE_FUNCTION order by templatecode) A
where rownum <= 40)
where rowno >= 21;
其中最内层的查询SELECT * FROM ROL_TEMPLATE_FUNCTION order by templatecode表示不进行翻页,根据templatecode 升序排列。ROWNUM < =40 和>=21控制分页查询的每页的范围。
第二种:利用分析函数row_number() 方法
select *
from (select t.*, row_number() over(order by t.templatecode) rowno from ROL_TEMPLATE_FUNCTION t)
where rowno between 21 and 40;
效率问题:第一种〉第二种
mysql 分页
不多说看sql语句:
select * from table WHERE … LIMIT 10; #返回前10行
select * from table WHERE … LIMIT 0,10; #返回前10行
select * from table WHERE … LIMIT 10,20; #返回第10-20行数据
mysql最简单,这里就不多说了。