Oracle 从表中随机行
我找到了从 Oracle 表中选择随机行的解决方案。实际上以随机方式对行进行排序,但您只能获取第一行以获得随机结果。
SELECT *
FROM table
ORDER BY dbms_random.value;
我只是不明白它是如何工作的。 ORDER BY之后应该是用于排序的列。我看到“dbms_random.value”返回一个小于零的值。这种行为可以解释还是就是这样?
谢谢
I found this solution for selecting a random row from a table in Oracle. Actually sorting rows in a random manner, but you can fetch only the first row for a random result.
SELECT *
FROM table
ORDER BY dbms_random.value;
I just don't understand how it works. After ORDER BY it should be a column used for sorting. I see that "dbms_random.value" returns a value lower than zero. This behavior can be explained or is just like that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你也可以这样想:
在这个例子中,数字 3 = 第三列
you could also think of it like this:
In this example the number 3 = the third column
当您按 dbms_random.value 排序时,Oracle 按表达式排序,而不是按列排序。对于每条记录,Oracle 计算一个随机数,然后按该数字排序。
类似地,是这样的:
你有一个基于函数的 order by 。
When you order by dbms_random.value, Oracle orders by the expression, not for a column.For every record Oracle calculate a random number, and then order by this number.
In a similar way, is like this:
You have an order by based on a function.