简体   繁体   English

使用准备好的语句的结果作为查询中的临时表

[英]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.

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