CREATE PROCEDURE mean_var(
IN s CHAR(15),
OUT mean FLOAT,
OUT var FLOAT
)
DECLARE cnt INT; //定义局部变量,要定义在begin和end外边
BEGIN
SET cnt=0;
SET mean = 0;
SET var = 0;
FOR a AS b CURSOR FOR
SELECT length FROM movies WHERE name = s; //这里边是循环体语句
DO
SET cnt=cnt+1;
SET mean=mean+length;
SET var=var+length*length;
END FOR
SET mean=mean/cnt;
SET var=var/cnt;
END