gpt4 book ai didi

MySQL 说 : Error #1064 - while using IF condition in sql

转载 作者:行者123 更新时间:2023-11-29 22:55:21 25 4
gpt4 key购买 nike

我在 sql 命令中收到此错误消息。我无法找出原因。请帮助我。

if ( SELECT * FROM `teams` WHERE `client_id`='3' and `member_id`='6' and `current`='1' ) then
begin
UPDATE `teams` SET `current`='0' WHERE `client_id`='3' and `member_id`='6' and `current`='1'
end ;
else
begin
INSERT INTO `teams`(`client_id`, `member_id`) VALUES ('3','33')
end;
end if;

这里我尝试更新列current(如果设置为1),否则插入一条新记录。

提交表单时,我需要在我的 php 文件中使用此 sql 命令。

下面是错误消息:

#1064 - 您的 SQL 语法有错误;

最佳答案

这不是 mysql 中的有效语句,有效语法如下。存储过程、函数或触发器中也允许使用 if-else。

if ( SELECT * FROM `teams` WHERE `client_id`='3' and `member_id`='6' and `current`='1' ) then
begin
UPDATE `teams` SET `current`='0' WHERE `client_id`='3' and `member_id`='6' and `current`='1'
end ;
else
begin
INSERT INTO `teams`(`client_id`, `member_id`) VALUES ('3','33')
end;
end if;

关于MySQL 说 : Error #1064 - while using IF condition in sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28737022/

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