mysql - 在 MySQL 中创建表变量

标签 mysql variables database-table

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

相关文章:

MySQL 使用 CASE .. WHEN 语法选择数据的适当方式

mysql - iReport 表连接问题并导致重复值

for循环中的Python变量赋值

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

c# - 数据表中的时区错误

sql - 创建数据库表

mysql - 优化未按预期使用索引的日期时间字段

python - mysql.connector.errors.ProgrammingError : Not all parameters were used in the SQL statement (Python, MySQL)

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

c# - 使用 C# 在 MySQL 数据库中创建表时出错