文章詳情頁
用一個實例講解DB2數據庫游標循環的問題
瀏覽:120日期:2023-11-08 19:30:31
本文中的存儲過程示例,預計的循環次數是yh表行數,由于SELECT IID INTO PINT FROM YH WHERE 0=1;不返回任何行,所以at_end后會立刻等于1(只循環一次就退出)。
DECLARE at_end INT DEFAULT 0; DECLARE PIID INTEGER DEFAULT 0 ;DECLARE PINT INTEGER DEFAULT 0 ; DECLARE not_found CONDITION FOR SQLSTATE '02000';--DECLARE PCOUNT INTEGER;DECLARE c1 CURSOR FOR SELECT IID FROM YH; DECLARE CONTINUE HANDLER FOR not_found SET at_end = 1; OPEN c1; SET PCOUNT=0;ins_loop: LOOP FETCH c1 INTO PIID; IF at_end <>0 THEN LEAVE ins_loop; END IF; SET PCOUNT=PCOUNT+1;SELECT IID INTO PINT FROM YH WHERE 0=1;END LOOP;
排行榜