好吧,我完全不知所措——这段代码曾经可以工作,现在突然不行了......
declare GetAllCodes cursor local for
select ac.activationCodePKID from ActivationCodes ac
left join OrdersLineItems od on ac.activationCodePKID = od.activationCodePKID
where od.activationCodePKID is null and ac.internalorderPKID is not null
and ac.campaignID is not null
and ac.enteredBy like 'ProcessRequest|Entitlement%'
RAISERROR ('step completed', 0, 1) WITH NOWAIT
open GetAllCodes
while (1=1)
begin
RAISERROR ('entering cursor', 0, 1) WITH NOWAIT
fetch next from GetAllCodes into @activationCodePKID
if (@@fetch_status <> 0)
begin
DEALLOCATE GetAllCodes
break
end
exec fixOrder @activationCodePKID, 6, 7
end
它似乎只是陷入了一个循环......我已经注释掉了 exec 语句,并且只是放入了一个 print 语句,但它一直在继续。“步骤完成”打印语句被打印,“进入光标”语句也是如此。然后什么都没有....只是挂起。查询本身返回 192 行,所以要循环,它应该循环 192 次,然后中断并结束。想法?
编辑:
我添加了这个:
declare @var varchar(10)
set @var = 'here: ' + cast(@@fetch_status as varchar(10))
RAISERROR (@var, 0, 1) WITH NOWAIT
...就在fetch next from GetAllCodes into @activationCodePKID
声明之后 - 仍然没有。'进入光标'仍然被打印,但它只是挂起......
编辑2:
我删除了很多东西,并在'declare cursor'语句之后添加了这个,看看我是否可以输出任何东西......
RAISERROR ('query done', 0, 1) WITH NOWAIT
open GetAllCodes
fetch next from GetAllCodes into @activationCodePKID
close GetAllCodes
deallocate GetAllCodes
仍然挂起......所以我拿出了'fetch statement',它似乎不再挂起。显然,它没有做任何事情,因为我没有让它做任何事情,但它完成了执行。
这让我想到了为什么 fetch 语句挂起。是否有一些服务器设置可能会影响这一点?一些内存问题?硬件问题?