为什么我在程序上遇到ERROR 1064(42000)mysql错误?

时间:2016-05-18 15:42:33

标签: mysql sql stored-procedures

我的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 ;

我收到以下错误:

  

错误1064(42000):您的SQL语法有错误;检查   手册,对应右边的MySQL服务器版本   要在google_place_id =''附近使用的语法按created_on排序   限制1); ew_outlet_id =(selec'第22行mysql> DELIMITER;

1 个答案:

答案 0 :(得分:0)

而是尝试使用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 = '');