-- 定义游标
DECLARE stuCursor CURSOR
FOR
SELECT stuNum,stuName,birthday FROM t_Student;
-- 定义结束标记
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-- 打开游标
OPEN stuCursor;
-- 循环
stuLoop:LOOP
-- 取游标中的数据
FETCH stuCursor INTO vstuNum,vstuName,vbirthday;
IF done = 1 THEN
LEAVE stuLoop;
END IF;
IF DATE(vbirthday) >= ‘1990-03-01‘ THEN
SELECT score INTO vscore FROM t_stu_score WHERE stuNum = vstuNum;
IF vscore >= p_score THEN
INSERT INTO t_stu_detail VALUES(NULL,vstuNum,vscore);
END IF;
END IF;
END LOOP stuLoop;