存储过程完整代码.
CREATE DEFINER=`root`@`localhost` PROCEDURE `cj_zongfen`()
BEGIN
DECLARE yw INT;#语文成绩
DECLARE sx INT;#数学成绩
DECLARE yy INT;#英语成绩
DECLARE d INT;
DECLARE nf BOOLEAN DEFAULT TRUE;
DECLARE zongfen_cursor CURSOR FOR SELECT yuwen,shuxue,yingyu,cid FROM cj;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET nf=FALSE;
OPEN zongfen_cursor;
FETCH zongfen_cursor INTO yw,sx,yy,d;
WHILE nf DO
UPDATE cj SET zongfen=yw+sx+yy WHERE cid=d;
FETCH zongfen_cursor INTO yw,sx,yy,d;
END WHILE;
END$$