CREATE DEFINER = CURRENT_USER PROCEDURE `sum_avg`()
BEGIN
declare st_NO char(12); #用来保存学号
declare st_Name varchar(20); #用来保存姓名
declare st_Sum float(5,2); #用来保存总分
declare st_Avg float(5,2); #用来保存平均分
declare s int; #s用来保存查询结果集中的记录数
declare i int default 1; #i作为循环变量,赋初值为1
declare s_a_cursor cursor for select st.student_NO,name,sum(score),avg(score)
from student st,scores sc
where st.student_NO = sc.student_NO group by student_NO;
#用来声明游标s_a_cursor,作为查询每个学生的学号、姓名、总分和平均分
select count(*)
from (select st.student_NO,name,sum(score),avg(score) from
student st,scores sc where st.student_NO = sc.student_NO group
by student_NO) as temp into s;
#用来保存共有多少条记录
open s_a_cursor;
while i <= s do
fetch s_a_cursor into st_NO,st_Name,st_Sum,st_Avg;
#从游标中提取第1条记录
select st_NO 学号,st_Name 姓名,st_Sum 总分,st_Avg 平均分;
set i = i + 1;
end while;
close s_a_cursor;
END;
我上面报错未定义游标 有大佬可以帮忙回答一下吗
有2个中文的分号
21、27、28 行三个分号不对
不知道你这个问题是否已经解决, 如果还没有解决的话: