本文中的存储过程示例预计的循环次数是yh表行数由于SELECT IID INTO PINT FROM YH WHERE =;不返回任何行所以at_end后会立刻等于(只循环一次就退出)
DECLARE at_end INT DEFAULT ;
DECLARE PIID INTEGER DEFAULT ;
DECLARE PINT INTEGER DEFAULT ;
DECLARE not_found CONDITION FOR SQLSTATE ;
DECLARE PCOUNT INTEGER;
DECLARE c CURSOR FOR
SELECT IID FROM YH;
DECLARE CONTINUE HANDLER FOR not_found
SET at_end = ;
OPEN c;
SET PCOUNT=;
ins_loop:
LOOP
FETCH c INTO PIID;
IF at_end <> THEN
LEAVE ins_loop;
END IF;
SET PCOUNT=PCOUNT+;
SELECT IID INTO PINT FROM YH WHERE =;
END LOOP;