CREATE OR REPLACE PROCEDURE SCHEMANAME.SP_CALLER() DYNAMIC RESULT SETS 1
P1:BEGIN
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE loc_cursor RESULT_SET_LOCATOR VARYING;
DECLARE CONTINUE HANDLER FOR SQLSTATE '23505' SET RET=SQLCODE;
SET PP = 1 ;
WHILE(PP < 5) DO
CALL SCHEMANAME.SPNAME(PP);
ASSOCIATE RESULT SET LOCATOR (loc_cursor) WITH PROCEDURE SCHEMANAME.SPNAME;
ALLOCATE cur CURSOR FOR RESULT SET loc_cursor;
L1: LOOP
FETCH C1 INTO column1, column2, ...;
IF SQLSTATE<>'00000' THEN
LEAVE L1;
END IF;
END LOOP L1;
CLOSE cur;
SET PP = PP + 1 ;
END WHILE;
END P1
狀況:
DB2寫SP如果SP裡面又對另一個SP做多次呼叫,會一直抓到第一次呼叫SP的結果。
貌似因為DB2版本問題,所以原寫法建立到新的DB2就有問題,取值時須再LOOP即可!感謝辜狗大師。
沒有留言:
張貼留言