当前位置: 数据库>oracle
Oracle row_number() over()解析函数高效实现分页
来源: 互联网 发布时间:2014-09-07
本文导语: 代码如下: create table T_NEWS ( ID NUMBER, N_TYPE VARCHAR2(20), N_TITLE VARCHAR2(30), N_COUNT NUMBER ) prompt Disabling triggers for T_NEWS... alter table T_NEWS disable all triggers; prompt Loading T_NEWS... insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT) values (1, 'IT', '爱it1', 100); i...
代码如下:
create table T_NEWS
(
ID NUMBER,
N_TYPE VARCHAR2(20),
N_TITLE VARCHAR2(30),
N_COUNT NUMBER
)
prompt Disabling triggers for T_NEWS...
alter table T_NEWS disable all triggers;
prompt Loading T_NEWS...
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (1, 'IT', '爱it1', 100);
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (2, '体育', '爱体育1', 10);
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (3, '体育', '爱体育2', 30);
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (4, 'IT', '爱it2', 300);
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (5, 'IT', '爱it3', 200);
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (6, '体育', '爱体育3', 20);
insert into T_NEWS (ID, N_TYPE, N_TITLE, N_COUNT)
values (7, '体育', '爱体育4', 60);
commit;
第一步:我先用rownum
--分页 row_number,不是rownum
--根据n_count从大到小排列,每页3条
SELECT ROWNUM r,t.* FROM t_news t
WHERE ROWNUM