在MySQL中创建表变量 [英] Create table variable in MySQL

查看:49
本文介绍了在MySQL中创建表变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个表变量来存储 MySQL 过程中表中的特定行. 例如.声明@tb表(id int,名称varchar(200))

I need a table variable to store the particular rows from the table within the MySQL procedure. E.g. declare @tb table (id int,name varchar(200))

这可能吗?如果是,怎么办?

Is this possible? If yes how?

推荐答案

它们在MySQL中不存在吗?只需使用一个临时表:

They don't exist in MySQL do they? Just use a temp table:

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

您可以使用TEMPORARY关键字 创建表时.临时的 该表仅对当前可见 连接,并被丢弃 连接时自动 关闭.这意味着两个不同 连接可以使用相同的临时 表名不冲突 彼此或与现有的 同名的非TEMPORARY表. (现有表被隐藏,直到 临时表被删除.)"

"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中创建表变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆