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

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

问题描述

我需要一个表变量来存储 MySQL 过程中表中的特定行.例如.声明@tb 表(id int,name 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 关键字创建表时.一个临时的表仅对当前可见连接,并被丢弃连接成功时自动关闭.这意味着两个不同的连接可以使用相同的临时表名不与彼此或与现有的同名的非临时表.(现有表被隐藏,直到临时表被删除.)"

"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天全站免登陆