使用Oracle的rownum可以实现一些有用的技巧,例如:
SELECT * FROM (
SELECT rownum AS rn, t.* FROM table_name t
) WHERE rn <= 10;
SELECT * FROM table_name ORDER BY dbms_random.value FETCH FIRST 10 ROWS ONLY;
SELECT * FROM (
SELECT rownum AS rn, t.* FROM table_name t GROUP BY column_name
) WHERE rn = 1;
SELECT * FROM table_name WHERE rownum <= 10;
需要注意的是,rownum是在查询结果返回之前计算的,所以在使用rownum时需要注意查询结果的排序和过滤条件,以避免结果不符合预期。