DB2 - 在存储过程中声明游标

时间:2014-10-01 10:18:49

标签: stored-procedures cursor db2 db2-luw

我发现了这个" DECLARE CURSOR"关于WWW的声明:

CREATE OR REPLACE PROCEDURE "APART21C"."FIND_VALID_ARZTNRN"
(OUT NoOfRows BIGINT)
RESULT SETS 1
LANGUAGE SQL
SPECIFIC SQL140905135133600
BEGIN

  DECLARE myARZTNR CHAR(7);
  DECLARE END_TABLE INT DEFAULT 0
  ;
  DELETE FROM APART21C.TMP_LANR07_CHECK
  ;
  DECLARE C1 CURSOR FOR
  SELECT DISTINCT Arztnr 
  FROM APART21C.DMP_LEV_TMP
  ;
  DECLARE CONTINUE HANDLER FOR NOT FOUND
   SET END_TABLE = 1
  ;
  OPEN C1
  ;
  FETCH C1 INTO myARZTNR
  ;
  WHILE END_TABLE = 0 DO

        INSERT INTO APART21C.TMP_LANR07_CHECK
        SELECT * FROM TABLE(APART21C.CHECK_ARZTNR_BY_CHECKSUM(myARZTNR)) AS ARZTNRCHECK;
        SET NoOfRows = NoOfRows + 1;

        FETCH C1 INTO myARZTNR;

  END WHILE
  ;
  CLOSE C1
  ;
END

错误消息是

"DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=<cursor declaration>;;<SQL statement>"

需要你的帮助

我是db2的初学者,我在MS SQL Server方面有更多经验。 语句&#34; SELECT * FROM TABLE(...&#34;调用函数返回一个表。 R上。

1 个答案:

答案 0 :(得分:0)

以下代码出现问题

DECLARE C1 CURSOR FOR   SELECT DISTINCT Arztnr   来自APART21C.DMP_LEV_TMP

我已更改如下并执行

DECELARE C1 CURSOR with HOLD FOR   SELECT Arztnr FROM DMP_LEV_TMP;