用Mysql语句创建存储过程,根据调用时提供的学生姓名查询该学生所修课程的课程信息,在过程体中将课程号、课程名和成绩输出到输出窗口,给出过程调用语句块。
时间: 2024-02-06 14:12:27 浏览: 43
好的,根据您的要求,下面是Mysql语句创建存储过程:
```mysql
DELIMITER //
CREATE PROCEDURE `get_course_info`(IN student_name VARCHAR(50))
BEGIN
DECLARE course_id INT;
DECLARE course_name VARCHAR(50);
DECLARE score INT;
DECLARE done INT DEFAULT FALSE;
DECLARE cur CURSOR FOR
SELECT course_id, course_name, score
FROM course
WHERE student_id = (SELECT id FROM student WHERE name = student_name);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur;
read_loop: LOOP
FETCH cur INTO course_id, course_name, score;
IF done THEN
LEAVE read_loop;
END IF;
SELECT CONCAT('Course ID: ', course_id, ', Course Name: ', course_name, ', Score: ', score) AS Course_Info;
END LOOP;
CLOSE cur;
END //
DELIMITER ;
```
然后,您可以使用以下语句调用该存储过程:
```mysql
CALL get_course_info('学生姓名');
```
请将 "学生姓名" 替换为您想要查询的学生姓名。
阅读全文