我正在编写一个存储过程。我在将变量与 LIMIT 和准备好的语句结合使用时遇到了一些问题。(见下面的代码)
该过程是正常创建的,但是当我调用它时,我收到一个错误,即变量a
未声明。有什么建议么?
delimiter //
drop procedure if exists shop1;
create procedure shop1()
begin
declare a varchar(255) default null;
declare counter int(4) default 0;
declare row_numbers int(4);
declare s varchar(255) default null;
select count(*) into row_numbers from salesmen;
WHILE counter< row_numbers+1 DO
set @s='select fio from salesmen into a Limit ? 1';
set @counter=counter;
prepare stmt from @s;
execute stmt using @counter;
SET counter=counter+1;
insert into warehouse.place (shop, fio) values (1, a);
END WHILE;
SET counter=0;
select count(*) into row_numbers from products;
WHILE counter< row_numbers+1 DO
SET counter=counter+1;
END WHILE;
end;
//