1.使用ROWNUM伪列查询
1.1.查询十条数据(rownum<=n)
SELECT ROWNUM,A.* FROM v_sjjx_unit_info A WHERE ROWNUM<=10
1.2.查询实体十条数据(between...and...)
SELECT * FROM v_sjjx_xsjbsjxx WHERE ROWNUM BETWEEN 0 AND 10
1.3.查询第二到第十条数据
SELECT * FROM (SELECT b.*,ROWNUM r FROM v_sjjx_unit_info b WHERE ROWNUM <= 10) WHERE r >2
注:查询中的rownum必须要有别名,否则还是不会查出记录来,这是因为rownum不是某个表的列,如果不起别名的话,无法知道rownum是子查询的列还是主查询的列。
1.4.两表联查,学生视图和学籍视图以学号为关联条件,查询两视图部分字段信息
SELECT * FROM
(SELECT ROWNUM RN,XZ.*
FROM (SELECT XS.XM,XJ.YXSH,XS.XH,XJ.ZYM,XS.XBM,XJ.SZNJ,XJ.XZ FROM v_sjjx_xsjbsjxx XS, v_sjjx_xjjbsjxx XJ WHERE XS.XH = XJ.XH ) XZ
WHERE ROWNUM<=10
) WHERE RN >(1-1)*10
2.分页查询另两种方法
2.1.使用MINUS(减去)方法 大减小
SELECT * FROM v_sjjx_unit_info WHERE ROWNUM<20 MINUS SELECT * FROM v_sjjx_unit_info WHERE ROWNUM<10
2.2.使用分析函数
SELECT * FROM(SELECT unit_id,unit_name,row_number()over(ORDER BY unit_id asc) rn FROM v_sjjx_unit_info) WHERE rn BETWEEN 10 AND 20