[英]Why am i getting syntax error in this query in mysql
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;
'為什么我會收到語法錯誤' - 你不能使用 if..end if outwith 存儲程序,mysql 不需要 begin..end 內 if..end if,if 語法應該是 if exists(select..),每個語句都需要終止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.