我怎么能模拟MySQL的一个数组变量? [英] How can I simulate an array variable in MySQL?
问题描述
据似乎 MySQL不具有数组变量。我应该用什么呢?
It appears that MySQL doesn't have array variables. What should I use instead?
似乎有两种选择建议:A 设置 - 类型的标和临时表。我联系到的问题提出了前者。但它是很好的做法,改为使用数组变量这些?另外,如果我有套去,这将是基于集合的成语相当于的foreach
的?
There seem to be two alternatives suggested: A set-type scalar and temporary tables. The question I linked to suggests the former. But is it good practice to use these instead of array variables? Alternatively, if I go with sets, what would be the set-based idiom equivalent to foreach
?
推荐答案
好吧,我一直在使用临时表,而不是数组变量。不是最大的解决方案,但它的工作原理。
Well, I've been using temporary tables instead of array variables. Not the greatest solution, but it works.
请注意,你并不需要正式定义他们的田地,只是用它们创造一个SELECT:
Note that you don't need to formally define their fields, just create them using a SELECT:
CREATE TEMPORARY TABLE IF NOT EXISTS my_temp_table
SELECT first_name FROM people WHERE last_name = 'Smith';
(另见不使用创建表创建一个从select语句临时表。)
(See also Create temporary table from select statement without using Create Table.)
这篇关于我怎么能模拟MySQL的一个数组变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!