为啥我在程序上收到 ERROR 1064 (42000) mysql 错误?
Posted
技术标签:
【中文标题】为啥我在程序上收到 ERROR 1064 (42000) mysql 错误?【英文标题】:Why am i getting ERROR 1064 (42000) mysql error on procedure?为什么我在程序上收到 ERROR 1064 (42000) mysql 错误? 【发布时间】:2016-05-18 15:42:33 【问题描述】:我的 mysql 5.5 程序有什么问题? 我正在尝试通过 linux 上的 mysql 客户端命令终端创建它。
DELIMITER //
CREATE procedure merge()
BEGIN
DECLARE old_outlet_id INT(10);
DECLARE new_outlet_id INT(10);
DECLARE gpid VARCHAR(255);
DECLARE v_finished INTEGER DEFAULT 0;
DEClARE cur CURSOR FOR select distinct google_place_id from service_providers_outlets group by google_place_id having count(google_place_id) > 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
OPEN cur;
getC: LOOP
FETCH cur INTO gpid;
IF v_finished = 1 THEN
LEAVE getC;
END IF;
SET old_outlet_id = (select id from service_providers_outlets o where google_place_id = gpid order by created_on limit 1);
SET new_outlet_id = (select id from service_providers_outlets o where google_place_id = gpid order by created_on desc limit 1);
select concat('old_outlet_id', old_outlet_id);
select concat('new_outlet_id', new_outlet_id);
if old_outlet_id != new_outlet_id then
update reviews_completed set outlet_id = new_outlet_id where outlet_id = old_outlet_id;
update service_providers_offers_outlet_link set outlet_id = new_outlet_id where outlet_id = old_outlet_id;
update service_providers_offers_redeemed set outlet_id = new_outlet_id where outlet_id = old_outlet_id;
update reviews_questions_outlet_link set outlet_id = new_outlet_id where outlet_id = old_outlet_id;
delete from dashboard_users_outlet_link where outlet_id = old_outlet_id;
delete from service_providers_outlets where id = old_outlet_id;
end if;
END LOOP getC;
CLOSE cur;
END //
DELIMITER ;
我收到以下错误:
ERROR 1064 (42000):您的 SQL 语法有错误;检查 与您的 MySQL 服务器版本相对应的手册 在 'o where google_place_id = '' order by created_on 附近使用的语法 限制 1); ew_outlet_id = (select' at line 22 mysql> DELIMITER ;
【问题讨论】:
【参考方案1】:尝试使用 max 和 min
SET old_outlet_id = (select max(id) from service_providers_outlets o where google_place_id = '' );
SET new_outlet_id = (select min(id) from service_providers_outlets o where google_place_id = '');
【讨论】:
以上是关于为啥我在程序上收到 ERROR 1064 (42000) mysql 错误?的主要内容,如果未能解决你的问题,请参考以下文章
为啥我是 laravel 抛出 SQLSTATE[42000]:语法错误或访问冲突:1064 错误
我在 Access 连接查询中收到 #Error 消息,但我不知道为啥
为啥我在 JavaFX 上收到 java.lang.IllegalStateException“不在 FX 应用程序线程上”?