原始記錄
select t
order by t
返回
STU_ID S_NAME C_ID S_BIRTHDAY
S
S
S
S
S
Oracle分頁查詢
第一種
select * from
(
select rownum r
)
where r between
返回
R STU_ID S_NAME C_ID S_BIRTHDAY
說明
STU_ID S_NAME C_ID S_BIRTHDAY
S
S
S
第二種
select b
(select rownum r
(select t
)b
where b
返回
R STU_ID S_NAME C_ID S_BIRTHDAY
正確!
所以Oracle分布查詢一定要用三層嵌套
select b
from (
select rownum r
select * from 表 order by 字段
) a
where rownum<=最大行
)b
where b
★★★關鍵點
為了程序的通用性
select b
from (
select rownum r
select * from (一個已經排序的數據集)
) a
where rownum<=最大行
)b
where b
如上面的查詢改為
select b
from (
select rownum r
select * from (select t
) a
where rownum<=最大行
)b
where b
或者其它查詢語句
select b
from (
select rownum r
select * from (select t
) a
where rownum<=最大行
)b
where b
★原始數據數據腳本(請在命令窗口中粘貼以下語句即可)
prompt PL/SQL Developer import file
prompt Created on
set feedback off
set define off
prompt Dropping T_STU
drop table T_STU cascade constraints;
prompt Creating T_STU
create table T_STU
(
STU_ID CHAR(
S_NAME CHAR(
C_ID CHAR(
S_BIRTHDAY DATE
S_SEX CHAR(
)
;
prompt Disabling triggers for T_STU
alter table T_STU disable all triggers;
prompt Loading T_STU
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
insert into T_STU (STU_ID
values (
commit;
prompt
prompt Enabling triggers for T_STU
alter table T_STU enable all triggers;
set feedback on
set define on
prompt Done
From:http://tw.wingwit.com/Article/program/Oracle/201311/18196.html