gpt4 book ai didi

mysql - 语法错误,意外的 Declare_sym

转载 作者:行者123 更新时间:2023-11-30 22:38:54 25 4
gpt4 key购买 nike

这是我的Mysql代码,它给出了一个 语法错误意外 Declare_sym

  delimiter @ 
create procedure StudentUpsert
(in in_regno int ,
in in_fNM varchar(50),
in in_mNM varchar(50),
in in_lNM varchar(50),

begin
declare regno_Count int ;
select Count(*) into regno_Count
fro students_info
if regno_Count > 0 then

update students_info
set firstname = in_fNM,
middlename = in_mNM,
lastname = in_lNM,
where regno = in_regno ;
else
insert into students_info
values (in_regno , in_fNM , in_mNM ,in_lNM );
end if ;
end @
delimiter ;
call StudentUpsert(9, 'ABC','NA','XYZ');

请帮忙 语法错误意外 Declare_sym

最佳答案

我在您发布的查询中没有看到任何 Declare_sym,但您的 SQL 代码确实存在语法错误,如下所示。不确定这些是否只是发布问题时的错字

 select Count(*) into regno_Count
fro students_info
^...... should be *from*

update students_info
set firstname = in_fNM,
middlename = in_mNM,
lastname = in_lNM, <----- remove this extra *,* here
where regno = in_regno ;

将您的程序主体更改为如下所示

  delimiter @ 
create procedure StudentUpsert
(in in_regno int ,
in in_fNM varchar(50),
in in_mNM varchar(50),
in in_lNM varchar(50))
begin

declare regno_Count int ;
select Count(*) into regno_Count
from students_info;

if regno_Count > 0 then
update students_info
set firstname = in_fNM,
middlename = in_mNM,
lastname = in_lNM
where regno = in_regno ;
else
insert into students_info
values (in_regno , in_fNM , in_mNM , in_lNM);
end if;
end@

关于mysql - 语法错误,意外的 Declare_sym,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31638050/

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