use stusys;
select * from score a,course b
where b.cname='数据库系统' and a.cno=b.cno;
delimiter //
create procedure P_math(in v_cname char(10),out v_grade char(20))
begin
#定义变量
declare v_avg decimal(4,2);
#将在表格中查找的数据赋值给变量v_avg
select avg(a.grade) into v_avg
from score a,course b
where b.cname=v_cname and a.cno=b.cno;
#条件判断
if v_avg>95 then
#将字符赋值给变量v_grade
set v_grade='成绩良好';
else
set v_grade='成绩一般';
end if;
end //
delimiter ;
#调用存储过程,定义用户变量要与存储过程的变量一致(个数和类型)
call P_math('数据库系统',@grade);
#用select查看结果
select @grade;
drop procedure P_math;