游标中的 order by 子句
如何对游标中的数据进行排序?我们可以使用order by子句
吗?
因为我需要先对数据进行排序。
How can I order data in a cursor? Can we use the order by clause
?
Because I need to sort the data first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
就像这样:
现实世界的例子:
Like that:
Real-world example:
我不确定您使用的是什么数据库,但在 SQL Server 中是可能的。
例如:
I am not sure what database you are using but it is possible in SQL Server.
for e.g.:
我知道这有一些问题,但可以使用以下方法解决
I know there was some problem with that but it can be solved using
由于某种原因,其他基于子查询的答案对我不起作用。它不断丢弃行,SQL Server 2012。这种特殊情况是从与表数据交叉的一些静态数据的视图中选择约 100 行。
解决方法是将光标声明为“forward_only static”:
链接:为什么使用 ORDER by 为选择打开的游标不反映对后续表的更新
有人知道有 order by 时默认的光标类型吗?为什么它不能总是适用于“静态”数据?
For some reason the other sub-query based answers did not work for me. It kept dropping rows, SQL Server 2012. This particular case was selecting ~100 rows from a view of some static data crossed with table data.
The cure was to declare the cursor as "forward_only static":
Link: Why an cursor opened for a select with ORDER by does not reflect updates to the subsequent table
Anyone know the default cursor type when there is an order by? Why wouldn't it always work for "static" data?
我有类似的问题。我对游标使用了表返回函数。
在函数的 select 语句中,ORDER BY 不起作用。
但在 CURSOR FOR 中,它起作用了。
I had similar problem. I used table return function for CURSOR.
in function's select statement, ORDER BY did not worked.
BUT in CURSOR FOR, it worked.