oracle分頁查詢

2021-05-27 22:40:44 字數 1620 閱讀 3678

資料庫表結構及記錄如下:

1.根據rowid來分:

16:31:48 sql> select * from passvehicleinfo p where rowid in ( select rid from (select rownum rn,rid from (select p.rowid rid,p.passvehicleid from passvehicleinfo p order by p.passvehicleid desc) view1 where rownum<10000) view2 where rn >9980) order by p.passvehicleid asc;

17:02:42 sql> select * from (select p.*,row_number() over (order by p.passvehicleid desc ) rk from passvehicleinfo p) where rk>9980 and rk<10000;

17:07:38 sql> select * from (select view1.*,rownum rn from (select p.* from passvehicleinfo p order by p.passvehicleid desc) view1 where rownum<10000) view2 where rn>9980;

1. rownum 分頁

select * from emp;

2. 顯示rownum[oracle分配的]

select e.*, rownum rn from (select * from emp) e;

rn相當於oracle分配的行的id號

3.挑選出6—10條記錄

先查出1-10條記錄

select e.*, rownum rn from (select * from emp) e where rownum <= 10;

如果後面加上rownum>=6是不行的,

4. 然後查出6-10條記錄

select * from (select e.*, rownum rn from (select * from emp) e where rownum <= 10) where rn >= 6;

5. 幾個查詢變化

a. 指定查詢列,只需要修改最裡層的子查詢

只查詢雇員的編號和工資

select * from (select e.*, rownum rn from (select ename, sal from emp)

e where rownum <= 10) where rn >= 6;

b. 排序查詢,只需要修改最裡層的子查詢

工資排序後查詢6-10條資料

select * from (select e.*, rownum rn from (select ename, sal from emp order

by sal) e where rownum <= 10) where rn >= 6;

ORACLE分頁查詢

單錶分頁 start num 起始行號 end num 截止行號 select t.from select s.rownum rn from table s where rownum end num t where rn start num 多表分頁 select from select temp....

Oracle分頁查詢

oracle的分頁查詢語句基本上可以按照本文給出的格式來進行套用。分頁查詢格式 select from select a.rownum rn from select from table name a where rownum 40 where rn 21 其中最內層的查詢select from t...

oracle 分頁查詢

1 要把rowid來分 select from t xiaoxi where rowid in select rid from select rownum rn,rid from select rowid rid,cid from t xiaoxi order by cid desc where r...