问题描述
似乎 MySQL 没有数组变量.我应该用什么代替?
It appears that MySQL doesn't have array variables. What should I use instead?
似乎建议了两种替代方案:集合类型标量和临时表.我链接到的问题表明前者.但是使用这些而不是数组变量是一种好习惯吗?或者,如果我使用集合,那么与 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:
DROP TEMPORARY TABLE IF EXISTS my_temp_table;
CREATE TEMPORARY TABLE my_temp_table
SELECT first_name FROM people WHERE last_name = 'Smith';
(另请参见不使用创建表从选择语句创建临时表.)
这篇关于如何在 MySQL 中模拟数组变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)