Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sql server游标卡在循环中_Sql_Sql Server_Sql Server 2008_Tsql_Database Cursor - Fatal编程技术网

sql server游标卡在循环中

sql server游标卡在循环中,sql,sql-server,sql-server-2008,tsql,database-cursor,Sql,Sql Server,Sql Server 2008,Tsql,Database Cursor,好的,我完全不知所措-这段代码过去是有效的,现在突然不 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

好的,我完全不知所措-这段代码过去是有效的,现在突然不

    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
…就在
fetch next from GetAllCodes to@ActivationDepkid
语句之后-仍然是空的。“输入光标”仍然会被打印,但它只是挂起

编辑2:

我去掉了很多东西,并在“declarecoursor”语句之后添加了这个,看看是否可以输出任何东西


RAISERROR ('query done', 0, 1) WITH NOWAIT 
open GetAllCodes 
fetch next from GetAllCodes into @activationCodePKID  
close GetAllCodes 
deallocate GetAllCodes 
仍然挂着。。。于是我拿出了“fetch语句”,它似乎不再挂起了。显然,它什么也没做,因为我没有让它做任何事情,但它完成了执行


这让我想到了fetch语句挂起的原因。是否存在可能影响此操作的服务器设置?一些内存问题?硬件问题?

我猜,@@fetch\u状态返回的不是0,例如-1或-2


也许可以看看里面到底有什么;这应该会给你一个错误的线索。

我的猜测是,@@fetch\u status返回的不是0,例如-1或-2


也许可以看看里面到底有什么;这应该会给你一个错误的线索。

光标的结构是这样的,有什么原因吗

通常,游标是这样构建的:

declare @dbName varchar(max);
declare myCursor cursor for select [name] from sys.databases;
open myCursor;
fetch next from myCursor into @dbName;

while (@@fetch_status = 0)
begin
  print @dbName;
  fetch next from myCursor into @dbName;
end;

close myCursor;
deallocate myCursor;
每当他们陷入一个查找中时,都是因为fetch状态没有设置为零(对我来说,通常的原因是缺少“fetch next”)

--

编辑:
你能检查一下活动监视器,看看这段SQL是否在运行吗?有僵局吗

光标的这种结构有什么原因吗

通常,游标是这样构建的:

declare @dbName varchar(max);
declare myCursor cursor for select [name] from sys.databases;
open myCursor;
fetch next from myCursor into @dbName;

while (@@fetch_status = 0)
begin
  print @dbName;
  fetch next from myCursor into @dbName;
end;

close myCursor;
deallocate myCursor;
每当他们陷入一个查找中时,都是因为fetch状态没有设置为零(对我来说,通常的原因是缺少“fetch next”)

--

编辑:
你能检查一下活动监视器,看看这段SQL是否在运行吗?有僵局吗

这样试过了,还是没有骰子。我还尝试了更多的东西,对问题进行了一些编辑,并将其缩小到“fetch”语句。这样尝试,仍然没有成功。我还尝试了更多的方法对问题进行了一些编辑,并将其缩小到“fetch”语句。看不到@fetch\u状态值-似乎是“fetch”语句本身导致了问题..看不到@fetch\u状态值-似乎是“fetch”语句本身导致了问题。。