[英]Using result of prepared statement as temp table in query
If I have the output of a prepared statement; 如果我有准备好的语句的输出; how do I use it as the source of my query?
如何使用它作为查询的来源?
CALL `myProcedure`;
PREPARE stmnt FROM @allSQL;
EXECUTE stmnt;
DEALLOCATE PREPARE stmnt;
So, I get an output from the EXECUTE stmnt;
因此,我从
EXECUTE stmnt;
获得了输出EXECUTE stmnt;
(let's call it tmp
) and I would like to run a query along the lines of: (我们称它为
tmp
),我想按照以下方式运行查询:
SELECT * FROM (EXECUTE stmnt) AS tmp WHERE this = that;
You could prepare a CREATE TEMPORARY TABLE
statement that contains the result of the query: 您可以准备一个包含查询结果的
CREATE TEMPORARY TABLE
语句:
SET @createSQL = CONCAT('CREATE TEMPORARY TABLE tmp AS ', @allSQL);
PREPARE stmt FROM @createSQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT * FROM tmp WHERE this = that;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.