huhaifeng123 2015-09-22 02:04 采纳率: 100%
浏览 5599
已采纳

存储过程 游标 while @@fetch_status=0 死循环

这段存储过程加了 while @@fetch_status=0 后会进入死循环 注释这行就可以运行成功 求大神指导

 declare @systems varchar(200) --查询的此服务的其他消费系统
        begin--7 
            set @out=@out+'<TargetSysList>'
            declare test cursor 
            for select c_user_number from ESB_CONSUME_SYSTEM where c_code = @fid and c_is_examine='1'      
            open test
            fetch next from test into @systems
            --while @@fetch_status=0
            begin --10      
                if(@systems<>@system)
                begin --8
                    set @out=@out+'<TargetSysCode>'+@systems+'</TargetSysCode>'
                end --8         
            end--10
            close test
            deallocate test
        begin --9
            set @out=@out+'</TargetSysList></MGREntry>'
        end --9   
        set @out1=@out 
        end--7    
  • 写回答

1条回答 默认 最新

  • sliang733 2015-09-22 02:12
    关注

    你不取下1行,当然@@fetch_status永远等于0啊!

    fetch next from test into @systems
    while @@fetch_status=0
    begin --10

    if(@systems<>@system)
    begin --8
    set @out=@out+''+@systems+''
    end --8

    ** fetch next from test into @systems**
    end--10

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?