DECLARE
@ChannelPing NVARCHAR(20),
@num int
--声明游标
DECLARE CustomerCursor CURSOR FOR SELECT ChannelPing FROM dbo.TChannelAttr
--打开游标
OPEN CustomerCursor
--读取第一条数据
Fetch next from CustomerCursor into @ChannelPing
PRINT '第一个频道是:'+ @ChannelPing
--循环读取接下来的所有数据
SET @num=1
while (@@fetch_status=0)
BEGIN
select @num=@num+1
Fetch next from CustomerCursor into @ChannelPing --这条语句一定要放在执行语句的下面,此处没有执行语句
print '第'+cast(@num as varchar)+'个频道是:'+@ChannelPing
END
--关闭游标
CLOSE CustomerCursor
--删除游标
DEALLOCATE CustomerCursor
游标实践1【鸡蛋】
最新推荐文章于 2024-06-13 10:40:34 发布