分页排序
查询SQL
SELECT
*
FROM
(
SELECT
ROWNUM
RN
,
T.
*
FROM
(
SELECT
EMPNO
,
ENAME
,
JOB
FROM
EMP
)
T
WHERE
ROWNUM
<=
5
)
S
WHERE
S.RN
>
2
查询结果
![](https://i-blog.csdnimg.cn/blog_migrate/ebf39213ecefb7cb067710458090fdf7.png)
随机取前n条数据
SELECT
ROWNUM
RN
,
T.
*
FROM
(
SELECT
EMPNO
,
ENAME
,
JOB
,
DBMS_RANDOM.VALUE
FROM
EMP
ORDER
BY
DBMS_RANDOM.VALUE
)
T
WHERE
ROWNUM
<=
3
获取所有的数据,每行数据生成一个随机数,然后根据随机数进行排序,最终得到排在前三的
![](https://i-blog.csdnimg.cn/blog_migrate/1bc9ee9056289aa22bef72394fa70dd0.png)