SQL Server游标应用实例

-申明一个游标
DECLARE MyCursor CURSOR	
	FOR SELECT TOP 5 FBookName,FBookCoding FROM TBookInfo

--打开一个游标	
OPEN MyCursor

--循环一个游标
DECLARE @BookName nvarchar(2000),@BookCoding nvarchar(2000)
	FETCH NEXT FROM  MyCursor INTO @BookName,@BookCoding
WHILE @@FETCH_STATUS =0
	BEGIN
		print 'name'+@BookName
		FETCH NEXT FROM  MyCursor INTO @BookName,@BookCoding
	END	

--关闭游标
CLOSE MyCursor
--释放资源
DEALLOCATE MyCursor

posted on 2011-09-09 11:01  李国清  阅读(319)  评论(0编辑  收藏  举报

导航