How to request a random row in SQL?

前端 未结 29 3032
孤城傲影
孤城傲影 2020-11-21 06:45

How can I request a random row (or as close to truly random as is possible) in pure SQL?

29条回答
  •  温柔的废话
    2020-11-21 07:30

    There is better solution for Oracle instead of using dbms_random.value, while it requires full scan to order rows by dbms_random.value and it is quite slow for large tables.

    Use this instead:

    SELECT *
    FROM employee sample(1)
    WHERE rownum=1
    

提交回复
热议问题