日期:2014-05-17  浏览次数:20644 次

游标的问题,麻烦高手看下


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_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
------------这里是少了的
fetch next from mycursor into @name;
------------这里是少了的
end
close mycursor
deallocate 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……