Mysql存储过程问题

时间:2009-08-24 10:07:35

标签: mysql stored-procedures

创建以下过程时,我收到以下错误消息:

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
'd_query;
 set d_result = execute stmt;
 deallocate prepare stmt; ' at line 15

但检查后我看不到错误。第15行涉及'如果d_query不为null,那么'。

这是真正的错误吗?或者接受执行作为d_result的赋值是不是很高兴?

非常感谢任何帮助。

delimiter |
create procedure runtests()
begin
  declare d_test_id char(20);
  declare d_query text;
  declare d_result text;

  declare cur cursor for select test_id, query, result from datavalidator order by test_id;

  open cur;

  repeat
    fetch cur into d_test_id, d_query, d_result;

    if d_query is not null then
      prepare stmt from d_query;
      set d_result = execute stmt;
      deallocate prepare stmt;

      update datavalidator set result = d_result;
    end if;
  until done end repeat;

  close cur;
end;
|
delimiter ; |

1 个答案:

答案 0 :(得分:1)

“请注意,文字字符串表达式或用户变量是指定要准备的语句的唯一方法。”来自this documentation

尝试在准备之前尝试将值写入用户变量,可能类似于:

set @q_sql = d_query;

...或直接写入fetch行中的用户变量。