有没有办法从PL/PGSQL中的光标中获取随机元素?
我正在研究PostgreSQL中的示例,在与光标打交道时,我找不到一种获取单个随机元素的方法。
我已经看到了许多文章和文档,但是似乎没有办法这样做。输出将是光标的随机数,即光标的随机元素。
I'm studying examples in PostgreSQL, and I can't find a way to get a single random element when dealing with a cursor.
I have seen many articles and documentation, but there seems to be no way to do it.The output would be a random number from the cursor, that is, a random element from the cursor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用光标。而是使用返回单个随机值并将其分配给变量的查询:
Don't use a cursor. Instead, use a query that returns a single random value and assign it to a variable:
使用本地表的测试案例:
A test case using a local table: