gpt4 book ai didi

mysql - 在MySQL中创建表变量

转载 作者:行者123 更新时间:2023-11-29 21:14:30 25 4
gpt4 key购买 nike

我需要一个表变量来存储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/36074633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com