Oracle分頁查詢

2021-10-01 04:33:01 字數 1390 閱讀 9868

.按rownum來分*

select * from (select t.*,rownum rn from(select * from t_xiaoxi order by cid desc)t where rownum<10000) where rn>9980;

其中t_xiaoxi為表名稱,cid為表的關鍵字段,取按cid降序排序後的第9981-9999條記錄,t_xiaoxi表有70000多條記錄。

//測試通過的分頁查詢okokok

select * from (select a1.*, rownum rn from(select ename,job from emp) a1 where rownum<=10)where rn>=5;

下面最主要介紹第三種:按rownum來分

rownum 分頁

select * from emp;

顯示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;

用查詢結果建立新錶.

這個命令是一種快捷的建表方式

create table mytable (id, name, sal, job, deptno) as select empno, ename,

sal, job, deptno from emp;

建立好之後,desc mytable;和select * from mytable;看看結果如何?

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...