七月流火 发表于 2006-6-7 10:54

小小菜鸟向大家请教一个问题

<P>小小菜鸟向大家请教一个问题<BR>能告诉我这段代码里面究竟出了什么问题吗<BR>本算法的目的:根据表中的 post_value 字段找出符合条件的记录<BR>谢谢大家了!<BR>declare t_media_post_cursor cursor for<BR>select post_id,post_mobilenum,post_value<BR>from t_media_post<BR>open t_media_post_cursor<BR>go<BR>declare @count int(1),@i int(3),@subvalue varchar(5)<BR>declare @post_id int(3),@post_mobilenum varchar(15),@post_value varchar(255)<BR>set @count=0<BR>set @i=0<BR>fetch next from t_media_post_cursor<BR>into @post_id,@post_mobilenum,@post_value <BR>while @@fetch_status &lt;&gt; -1<BR>begin<BR> while @count&lt;=3<BR>  begin<BR>   @subvalue=substr(@post_value,1,@i)<BR>   if @subvalue not in ('A','C','D','F','G','H','K','L')<BR>    @count=@count+1<BR>   @i=@i+1 <BR>   end if  <BR>  end<BR>  if @count&lt;3<BR>  print ' @post_id,@post_mobilenum,@post_value'<BR>  end if<BR>fetch next from t_media_post_cursor<BR>into @post_id,@post_mobilenum,@post_value <BR>end<BR>close t_media_post_cursor<BR>DEALLOCATE t_media_post_cursor</P>

weizy 发表于 2006-8-1 15:08

while @count&lt;=3<BR>  begin<BR>   @subvalue=substr(@post_value,1,@i)<BR>   if @subvalue not in ('A','C','D','F','G','H','K','L')<BR>    @count=@count+1<BR>   @i=@i+1 <BR>   end if  <BR>  end<BR>这里if 一旦为True时, i和count都不变了, 可能会造成死循环吧, 最好对if加个else 做跳出while处理

页: [1]

编程论坛