日期:2014-05-18  浏览次数:20567 次

SQL游标问题请教
我写了一个游标,内容如下:
SQL code
DECLARE @A001 char(100),@A005 Numeric(16,6),@A006 Numeric(16,6) 
SELECT  @A006 = 0
DECLARE CAAA  CURSOR  FOR
SELECT A001,A005 FROM @AA FOR UPDATE
OPEN CAAA
Fetch Next FROM CAAA INTO @A001,@A005
WHILE(@@FETCH_STATUS = 0)
  UPDATE @AA SET A006 = @A006 + A005 FROM @AA WHERE CURRENT OF CAAA
  Fetch Next FROM CAAA INTO @A001,@A005
CLOSE CAAA
DEALLOCATE CAAA


我的游标是放在一个函数里面,不加游标,函数执行行就5行数据。
但是加的游标后,1个小时都没查询结果出来,问题出在哪里?

------解决方案--------------------
SQL code

DECLARE @A001 char(100),@A005 Numeric(16,6),@A006 Numeric(16,6) 
SELECT  @A006 = 0
DECLARE CAAA  CURSOR  FOR
SELECT A001,A005 FROM @AA FOR UPDATE
OPEN CAAA
Fetch Next FROM CAAA INTO @A001,@A005
WHILE(@@FETCH_STATUS = 0)
BEGIN
  UPDATE @AA SET A006 = @A006 + A005 FROM @AA WHERE CURRENT OF CAAA
  Fetch Next FROM CAAA INTO @A001,@A005
END
CLOSE CAAA
DEALLOCATE CAAA