-- 创建临时表用动态sql创建 set @sqls = concat('create temporary table ',`temptableTableName`,'(variable varchar(200),variableValue varchar(200),variableDate varchar(50))'); prepare stmt1 from @sqls; #准备好sql语句 execute stmt1; #执行sql deallocate prepare stmt1; #释放准备 -- 执行插入 set @s = concat('insert into ',`temptableTableName`,'(variable,variableValue,variableDate) values(''1'',''1'',''1''),(''2'',''2'',''2''),(''3'',''3'',''3'')'); select @s; prepare stmt2 from @s; execute stmt2; drop prepare stmt2; -- 批量插入 set @s2 = concat('insert into t_dd_aa(variable,variableValue,variableDate) select variable,variableValue,variableDate from ', `temptableTableName`); select @s2; prepare stmt3 from @s2; execute stmt3; drop prepare stmt3;
官方文档:https://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html
网文:https://blog.csdn.net/ashic/article/details/52135717
标签:variableDate,set,Statements,prepare,Prepared,variableValue,sql,variable From: https://www.cnblogs.com/luna-hehe/p/17807449.html