Ошибка подготовки и выполнения процедуры MySQL - PullRequest
0 голосов
/ 01 мая 2018

У меня есть рабочая процедура:

   drop procedure if exists parents;
   create procedure parents(in related int(11),out counted int(11))
   begin
    drop temporary table if exists ids;
    create temporary table ids(id int(11));
    while related<>0 do
     select category.related into related from category where category.id=related;
     insert into ids(id) values(related);
    end while;
    select count(*) into counted from ids;
   end;

Но я хочу создать динамическое имя таблицы. Поэтому я хотел бы построить что-то вроде этого:

   drop procedure if exists parents;
   create procedure parents(in related int(11),name varchar(22),out counted int(11))
   begin
    drop temporary table if exists ids;
    create temporary table ids(id int(11));
    while related<>0 do
     prepare statement from concat("select t.related into related from ",name," t where t.id=?");
     execute statement using related;
     insert into ids(id) values(related);
    end while;
    select count(*) into counted from ids;
   end;

Но я получаю ошибку логическая ошибка.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...