我需要一个表变量来存储 MySQL 中表中的特定行程序。 例如。声明@tb 表 (id int,name varchar(200))
这可能吗?如果是怎么办?
最佳答案
它们在 MySQL 中不存在,是吗?只需使用临时表:
CREATE PROCEDURE my_proc () BEGIN
CREATE TEMPORARY TABLE TempTable (myid int, myfield varchar(100));
INSERT INTO TempTable SELECT tblid, tblfield FROM Table1;
/* Do some more stuff .... */
来自 MySQL here
"You can use the TEMPORARY keyword when creating a table. A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed. This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.)"
关于mysql - 在 MySQL 中创建表变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524858/