加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle系列:(16)分页

发布时间:2020-12-12 16:00:31 所属栏目:百科 来源:网络整理
导读:回顾mysql分页 用limit关键字 查询users表中前二条记录 select*fromuserslimit0,2 或 select*fromuserslimit2; 0表示第一条记录的索引号,索引号从0开始 2表示最多选取二个记录 查询出users前三条记录 select*fromuserslimit0,3 或 select*fromuserslimit3

回顾mysql分页

用limit关键字


查询users表中前二条记录

select*fromuserslimit0,2

select*fromuserslimit2;

0表示第一条记录的索引号,索引号从0开始

2表示最多选取二个记录


查询出users前三条记录

select*fromuserslimit0,3

select*fromuserslimit3


查询出users第2条到第4条记录

select*fromuserslimit1,3;



回顾hibernate分页API

Query.setFirstResult(0);
Query.setMaxResult(3);






什么是rownum,有何特点

1)rownum是oracle专用的关健字

2)rownum与表在一起,表亡它亡,表在它在

3)rownum在默认情况下,从表中是查不出来的

4)只有在select子句中,明确写出rownum才能显示出来

5)rownum是number类型,且唯一连续

6)rownum最小值是1,最大值与你的记录条数相同

7)rownum也能参与关系运算

* rownum = 1 有值

* rownum < 5 有值

* rownum <=5 有值

* rownum > 2 无值

* rownum >=2 无值

* rownum <>2 有值 与 rownum < 2 相同

* rownum = 2 无值

8)基于rownum的特性,我们通常rownum只用于<或<=关系运算


显示emp表中3-8条记录(方式一:使用集合减运算)

selectrownum"伪列",emp.*fromempwhererownum<=8
minus
selectrownum,emp.*fromempwhererownum<=2;


显示emp表中2-8条记录(方式二:使用子查询,在from子句中使用,重点)

selectxx.*
from(selectrownumids,emp.*fromempwhererownum<=8)xx
whereids>=2;

注意:在子查询中的别名,不可加""引号

wKiom1fQJQHT1mbwAABgngcHi5k999.png


显示emp表中5-9条记录

selectyy.*
from(selectrownumids,emp.*fromempwhererownum<=9)yy
whereids>=5;

wKioL1fQJVThRWWEAAAix7ldCpQ105.png

注意:在项目中,from后面可能有真实表名,也可能用子查询看作的表名,

同时真实表和子查询看作的表要做连接查询

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!


    推荐文章
      热点阅读