我有一个存储过程,如下所示。
在这里,我创建了一个名为tempDesTable的临时表,并将来自数据库的数据放入其中。现在,我必须从另一个选择查询中放入其他数据。但它显示Error Code : 1327 Undeclared variable: tempDesTable
BEGIN
CREATE TEMPORARY TABLE tempDesTable AS (SELECT ID, FirstName, LastName FROM t_users WHERE `DesignationID` = p_DesignationID AND BranchID = 0);
SELECT ID, FirstName, LastName INTO `tempDesTable` FROM t_users WHERE `DesignationID` = p_DesignationID AND BranchID = p_BranchID;
END$$
最佳答案
您需要使用insert ... select而不是select ... into
INSERT INTO tempDesTable SELECT ID, FirstName, LastName FROM t_users
WHERE `DesignationID` = p_DesignationID AND BranchID = p_BranchID;
关于mysql - 使用mysql存储过程创建并插入临时表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17608617/