简体   繁体   中英

MySQL Use prepare statement result in other query

I want to use prepare statement result to fill my temporary table. Is it possible? (If it's matter I trying to do it within stored procedure.)

I suppose something like this:

SET @table_name = 'my_table';
SET @query = CONCAT('SELECT * FROM ', @table_name);
PREPARE statement FROM @query;
INSERT INTO tmp_table FROM statement;
DEALLOCATE PREPARE statement;

Create temporary table first

SET @table_name = 'my_table';
SET @query = CONCAT('CREATE TEMPORARY TABLE tmp_table AS SELECT * FROM ', @table_name);
PREPARE statement FROM @query;
EXECUTE statement ;
DEALLOCATE PREPARE statement;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM