当前位置: 代码迷 >> Sql Server >> 游标的有关问题,麻烦高手看上
  详细解决方案

游标的有关问题,麻烦高手看上

热度:45   发布时间:2016-04-27 11:25:00.0
游标的问题,麻烦高手看下


Alter proc pro_getName
as
declare @name varchar(200)
declare mycursor cursor Scroll for select mtvnam from mtv v where v.mtvtyp='来源'
open mycursor
fetch next from mycursor into @name;
while(@@FETCH_STATUS=0)
begin
print @name
end
close mycursor
deallocate mycursor


exec pro_getName 发现是个死循环,查询只是9条数据,为什么那?
还有就是sql中循环有几种写法?麻烦举个例子,谢谢

------解决方案--------------------
SQL code
Alter proc pro_getNameasdeclare @name varchar(200)declare mycursor cursor Scroll for select mtvnam from mtv v where v.mtvtyp='来源'open mycursorfetch next from mycursor into @name;while(@@FETCH_STATUS=0)beginprint @name------------这里是少了的fetch next from mycursor into @name;------------这里是少了的endclose mycursordeallocate mycursor
------解决方案--------------------
探讨
Alter proc pro_getName
as
declare @name varchar(200)
declare @where varchar(200)
declare mycursor cursor Scroll for select mtvnam from mtv v where v.mtvtyp='来源'
open mycursor
fetch next from myc……
  相关解决方案