根据查询条件动态拼接表名
# 测试数据
create table temp1(id int , name varchar(50));
create table temp2(id int , name varchar(50));
insert into temp2 values(2,'里斯');
insert into temp1 values(1,'张三');
# 存储过程
DELIMITER $$
CREATE PROCEDURE demo1(in id int )
begin
set @mysql=concat('SELECT * from temp',id%10);
prepare sm from @mysql;
set@mysql=null;
execute sm;
END $$
DELIMITER ;
# 执行
call demo1(1);
标签:存储,set,int,into,mysql,过程,id
From: https://www.cnblogs.com/mznsndy/p/16731517.html