create procedure stc_info(in Tid char(8), in type int, out info varchar(10)) IF type = 1 then set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR); ELSEIF type = 2 then set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR); ELSE set type = 'error!!!'; end if;为什么错误
时间: 2024-02-10 20:07:45 浏览: 64
pcb-2020-10-21_STC8G1K08A_stc8g_STC8Goled_pcb
5星 · 资源好评率100%
这个错误可能是因为在 IF 语句中缺少了 BEGIN 和 END 标记,应该将代码修改如下:
```
create procedure stc_info(in Tid char(8), in type int, out info varchar(10))
BEGIN
IF type = 1 THEN
set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR);
ELSEIF type = 2 THEN
set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR);
ELSE
set info = 'error!!!';
END IF;
END;
```
在存储过程中,需要使用 BEGIN 和 END 来标记 IF 语句的开始和结束。此外,最后一个 ELSE 语句应该将 info 设置为 'error!!!',而不是将 type 设置为 'error!!!'。
阅读全文