gpt4 book ai didi

mysql - SQL错误: 1064 You have an error in your SQL syntax;

转载 作者:行者123 更新时间:2023-11-29 12:51:57 27 4
gpt4 key购买 nike

我对下一个代码有疑问:

create function proc1 (id int)
returns float
begin
declare sum float
select sum = (note1+note2+note3)/3 from test1.note where note.id=id;
return sum;
end

我收到此错误:

#1064 - 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 'select sum = (note.note1+note.note2+note.note3)/3 from test1.note where note.id=' at line 5 

我花了很多时间寻找解决方案,但没有找到解决方案:(

最佳答案

delimiter |
create function proc1 (id int)
returns float
begin
declare sum float;
select (note1+note2+note3)/3 into sum from test1.note where note.id=id;
return sum;
end
|
delimiter ;

您有多个错误:

  • 未定义分隔符。否则数据库认为你的函数定义停在第一个 ; 这是错误的
  • 您需要使用select ... into。否则,您会收到“不允许从函数返回结果集”错误
  • 您在声明后忘记了分号

关于mysql - SQL错误: 1064 You have an error in your SQL syntax;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24595795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com