MySQL的存储过程declare语句报错
 CREATE PROCEDURE curdemo()
begin
  declare var_id varchar(32);
  declare var_number varchar(32);
  DECLARE var_model VARCHAR(32);
  declare rs cursor for select id,number from t_device_lending;
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;
  open rs;
  fetch next from rs into var_id,var_number;
  REPEAT
      IF NOT Done THEN
       select model_number into var_model from t_device_info where number = var_number;
       update t_device_lending_copy set model_number = var_model where id = var_id;
      END IF;

      FETCH NEXT FROM rs INTO id,number;

      UNTIL Done END REPEAT;

  /* 关闭游标 */
  CLOSE rs;  
end

报的错是“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 'declare var_id varchar(32)' at line 3”
我对了一下5.7.10的官方手册。declare的语法应该是正确的,怎么会报这种错?求大神解释。

2个回答

图片说明
end后面少了$$,所以引起了语法报错。

Explorer8
Explorer8 回复冬天perfect: DELIMITER $$这是个不成文的规定??
3 年多之前 回复
renjianqin_1984
冬天perfect 回复Explorer8:存储过程以DELIMITER $$开头,DELIMITER结尾。。。
3 年多之前 回复
Explorer8
Explorer8 是不是前面还要多个delimiter $$
3 年多之前 回复

变量 done 、id、number都没有声明。。。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问