ERROR 1064 (42000) at line 6: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; when sum(sjfk)>=5000 and sum(sjfk)<10000 then 'vip'; ' at line 6
时间: 2023-07-09 10:50:53 浏览: 158
这个错误可能是因为在 `return` 语句中出现了分号,而导致 MySQL 解析错误。请将 `return` 语句修改为以下形式:
```sql
return level;
```
也就是去掉分号,只返回变量 `level` 的值即可。这个问题在代码中出现在第 6 行附近。修改后的代码如下:
```sql
use sale;
delimiter $$
create function gkjb(nf int,xm varchar(10)) Returns varchar(10)
begin
declare level varchar(30) charset utf8;
select (case
when sum(sjfk)>=10000 then '超级vip'
when sum(sjfk)>=5000 and sum(sjfk)<10000 then 'vip'
when sum(sjfk)>=0 and sum(sjfk)<5000 then '一般会员'
else '非会员'
end) into level
from gk join xsd on gk.hyh=xsd.hyh
where name=xm and DATE_FORMAT(xsrq,'%Y')=nf;
return level;
end
$$
delimiter ;
select name as 姓名,gkjb(2015,name) as 级别 from gk;
```
请注意,修改后的代码中,`return` 语句的末尾没有分号。
阅读全文