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/14361114/

相关文章:

php - php-搜索查询

arrays - 批处理脚本 - 在 For 循环中创建动态变量名称或数组

sql - 从 xls (Excel) 文件创建 SQL 表

MySQL 查询 "IN"500,000 条记录

php - 如何返回其中包含 json 数组的 json 对象?

mysql - Joomla安装错误INSTL_ERROR_INITIALISE_SCHEMA

php - 按字段中的第二个和第三个文本对列表进行排序

php - 在 PHP 5 中如何通过引用传递对象?