1.环境:创建一个表
create table test (id number, buydate timestamp);
begin
for i in 1..10 loop
insert into test values(i,sysdate);
end loop;
end;
select * from test;
1 22-AUG-17 03.19.15.000000 PM
2 22-AUG-17 03.19.15.000000 PM
3 22-AUG-17 03.19.15.000000 PM
4 22-AUG-17 02.19.15.000000 PM
5 22-AUG-17 03.19.15.000000 PM
6 22-AUG-17 03.19.15.000000 PM
7 22-AUG-17 03.19.15.000000 PM
8 22-AUG-17 04.19.15.000000 PM
9 22-AUG-17 03.19.15.000000 PM
10 22-AUG-17 03.19.15.000000 PM
使用rownum分页排序sql语句如下:
--1
SELECT *
FROM ( SELECT P.*, ROWNUM AS RN
FROM (SELECT *
FROM TEST
WHERE 1 = 1
ORDER BY buydate DESC) P )
create table test (id number, buydate timestamp);
begin
for i in 1..10 loop
insert into test values(i,sysdate);
end loop;
end;
select * from test;
1 22-AUG-17 03.19.15.000000 PM
2 22-AUG-17 03.19.15.000000 PM
3 22-AUG-17 03.19.15.000000 PM
4 22-AUG-17 02.19.15.000000 PM
5 22-AUG-17 03.19.15.000000 PM
6 22-AUG-17 03.19.15.000000 PM
7 22-AUG-17 03.19.15.000000 PM
8 22-AUG-17 04.19.15.000000 PM
9 22-AUG-17 03.19.15.000000 PM
10 22-AUG-17 03.19.15.000000 PM
--1
SELECT *
FROM ( SELECT P.*, ROWNUM AS RN
FROM (SELECT *
FROM TEST
WHERE 1 = 1
ORDER BY buydate DESC) P )