我有一个工作程序:
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;
但是我得到一个错误布尔错误。