gpt4 book ai didi

mysql - 为什么我在 mysql 中的这个查询中出现语法错误

转载 作者:行者123 更新时间:2023-11-30 21:25:42 24 4
gpt4 key购买 nike

DB 新手,我正在编写查询,但需要帮助找出语法错误。查询:

SELECT IF (EXISTS(SELECT * FROM contact_address WHERE ad_ct_id = 1)) THEN
BEGIN
UPDATE contact_address set ad_city = 'Iraq'
END
ELSE
BEGIN
INSERT INTO contact_address (ad_ct_id, ad_type, ad_city)
VALUES (1, 'o', 'Iraq')
END
END IF;

错误:

ERROR 1064 (42000): 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 ') THEN
BEGIN
UPDATE contact_address set ad_city = 'Iraq'
END
ELSE
BEGIN
INSERT I' at line 1

谢谢

最佳答案

删除SELECT

IF (EXISTS(SELECT * FROM contact_address WHERE ad_ct_id = 1)) THEN
BEGIN
UPDATE contact_address set ad_city = 'Iraq'
END
ELSE
BEGIN
INSERT INTO contact_address (ad_ct_id, ad_type, ad_city)
VALUES (1, 'o', 'Iraq')
END
END IF;

关于mysql - 为什么我在 mysql 中的这个查询中出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59186508/

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