--> 构造测试数据 declare @tb table(pname varchar(50)) insert @tb select '电视机' union all select '电冰箱' union all select '洗衣机' union all select '空调' union all select '微波炉'--> 游标的使用 declare my_cursor cursor scroll dynamic for select pname from @tb open my_cursor declare @pname sysname fetch next from my_cursor into @pname while(@@fetch_status=0) begin print 'Product Name: ' + @pname fetch next from my_cursor into @pname end fetch first from my_cursor into @pname close my_cursor deallocate my_cursor--> 结果 /**Product Name: 电视机 Product Name: 电冰箱 Product Name: 洗衣机 Product Name: 空调 Product Name: 微波炉 **/
declare @tb table(pname varchar(50))
insert @tb
select '电视机' union all
select '电冰箱' union all
select '洗衣机' union all
select '空调' union all
select '微波炉'--> 游标的使用
declare my_cursor cursor scroll dynamic
for
select pname from @tb
open my_cursor
declare @pname sysname
fetch next from my_cursor into @pname
while(@@fetch_status=0)
begin
print 'Product Name: ' + @pname
fetch next from my_cursor into @pname
end
fetch first from my_cursor into @pname
close my_cursor
deallocate my_cursor--> 结果
/**Product Name: 电视机
Product Name: 电冰箱
Product Name: 洗衣机
Product Name: 空调
Product Name: 微波炉
**/