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/