在MySQL程序中,我想要从一个动态查询创建的临时表计数行,即
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Tbl as select * from dynamic_tbl;
描述临时tmp_Tbl; 说Field有15行,所以保存到会话变量@TotCols
再次从动态查询创建临时表: 描述临时tmp_Tbl; 说Field有4行,所以保存到会话变量@TotCols
答案 0 :(得分:0)
在存储例程的正文中,请尝试:
SET @create_tmp_table_sql = CONCAT(
'CREATE TEMPORARY TABLE IF NOT EXISTS tmp_tbl AS ',
'SELECT * FROM dynamic_tbl'
);
PREPARE create_tmp_table_stmt FROM @create_tmp_table_sql;
EXECUTE create_tmp_table_stmt;
DEALLOCATE PREPARE create_tmp_table_stmt;
SET @TotCols = (SELECT Count(*) FROM tmp_tbl);