光标示例问题 [英] Cursor Example Problem

查看:77
本文介绍了光标示例问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队,

请给我一个示例,说明如何声明游标和使用游标.

请编写一个简单的查询.

Hi Team,

kindly give me example how to declare cursor and use of cursor.

kindly write a simple query.

推荐答案

这是SQL 2005中的另一个示例,但是语法应该相同.

http://blog.ysatech.com/post/2009/08/02/SQL-2005-Cursor-Template.aspx [ ^ ]
here is another example in SQL 2005 but the syntax should be the same.

http://blog.ysatech.com/post/2009/08/02/SQL-2005-Cursor-Template.aspx[^]


更新:有关使用AdventureWorks的工作示例,请访问:SQL SERVER –光标的简单示例–光标示例第2部分

这是SQL Server游标的最简单示例.我一直在T-SQL中使用Cursor来使用它.
宣告@AccountID INT
宣告@getAccountID光标
SET @getAccountID =光标用于
SELECT Account_ID
来自帐户
OPEN @getAccountID
下一页
从@getAccountID到@AccountID
@@ FETCH_STATUS = 0
开始
打印@AccountID
下一页
从@getAccountID到@AccountID
END
CLOSE @getAccountID
释放@getAccountID
UPDATE: For working example using AdventureWorks visit : SQL SERVER – Simple Example of Cursor – Sample Cursor Part 2

This is the simplest example of the SQL Server Cursor. I have used this all the time for any use of Cursor in my T-SQL.
DECLARE @AccountID INT
DECLARE @getAccountID CURSOR
SET @getAccountID = CURSOR FOR
SELECT Account_ID
FROM Accounts
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @AccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
END
CLOSE @getAccountID
DEALLOCATE @getAccountID


这篇关于光标示例问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆