<tfoot id='fMFJw'></tfoot>

    <legend id='fMFJw'><style id='fMFJw'><dir id='fMFJw'><q id='fMFJw'></q></dir></style></legend>
    1. <small id='fMFJw'></small><noframes id='fMFJw'>

          <bdo id='fMFJw'></bdo><ul id='fMFJw'></ul>
      1. <i id='fMFJw'><tr id='fMFJw'><dt id='fMFJw'><q id='fMFJw'><span id='fMFJw'><b id='fMFJw'><form id='fMFJw'><ins id='fMFJw'></ins><ul id='fMFJw'></ul><sub id='fMFJw'></sub></form><legend id='fMFJw'></legend><bdo id='fMFJw'><pre id='fMFJw'><center id='fMFJw'></center></pre></bdo></b><th id='fMFJw'></th></span></q></dt></tr></i><div id='fMFJw'><tfoot id='fMFJw'></tfoot><dl id='fMFJw'><fieldset id='fMFJw'></fieldset></dl></div>

        将数组传递给 MySQL 存储例程

        时间:2023-08-19
      2. <tfoot id='hWqlS'></tfoot>
        • <bdo id='hWqlS'></bdo><ul id='hWqlS'></ul>
          <i id='hWqlS'><tr id='hWqlS'><dt id='hWqlS'><q id='hWqlS'><span id='hWqlS'><b id='hWqlS'><form id='hWqlS'><ins id='hWqlS'></ins><ul id='hWqlS'></ul><sub id='hWqlS'></sub></form><legend id='hWqlS'></legend><bdo id='hWqlS'><pre id='hWqlS'><center id='hWqlS'></center></pre></bdo></b><th id='hWqlS'></th></span></q></dt></tr></i><div id='hWqlS'><tfoot id='hWqlS'></tfoot><dl id='hWqlS'><fieldset id='hWqlS'></fieldset></dl></div>

          <small id='hWqlS'></small><noframes id='hWqlS'>

          • <legend id='hWqlS'><style id='hWqlS'><dir id='hWqlS'><q id='hWqlS'></q></dir></style></legend>

                    <tbody id='hWqlS'></tbody>

                  本文介绍了将数组传递给 MySQL 存储例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要将字符串数组作为参数传递给 MySQL 存储例程.该数组可能很长,并且其元素数量不固定.然后我想将字符串值放入一个包含一列的内存表中,以便我可以处理数据.我不知道这是否可以在 MySQL 中完成.也许需要一些肮脏的解决方法.

                  I need to pass an array of strings as parameter to a MySQL stored routine. The array could be long and its number of elements is not fixed. I then want to put the string values into an in-memory table with one column, so I can work with the data. I don't know if this can be done in MySQL. Maybe dirty workarounds are needed.

                  例如,我有字符串值:

                  Banana, Apple, Orange
                  

                  现在我想从我的 MySQL Fruits 表中获取有关这些水果的数据.伪代码:

                  Now I want to get data on these fruits from my MySQL Fruits table. Pseudo code:

                  create function GetFruits(Array fruitArray) 
                     declare @temp table as
                        fruitName varchar(100)
                     end
                  
                     @temp = convert fruitArray to table
                     select * from Fruits where Name in (select fruitName from @temp)
                  end
                  

                  Microsoft SQL Server 允许您使用 TEXT 数据类型并将数组作为 XML 字符串提交,从而快速创建内存表.但是,我认为 MySQL 中不可能使用这种技术.

                  Microsoft SQL Server allows you to use the TEXT datatype and submit the array as an XML string, swiftly creating the in-memory table. However, I don't think that technique is possible in MySQL.

                  任何有关如何执行此操作的帮助将不胜感激!

                  Any help on how to do this would be appreciated!

                  推荐答案

                  您可以在列表中传递一个字符串并使用 prepared statements 运行查询,例如-

                  You can pass a string with your list and use a prepared statements to run a query, e.g. -

                  DELIMITER $$
                  
                  CREATE PROCEDURE GetFruits(IN fruitArray VARCHAR(255))
                  BEGIN
                  
                    SET @sql = CONCAT('SELECT * FROM Fruits WHERE Name IN (', fruitArray, ')');
                    PREPARE stmt FROM @sql;
                    EXECUTE stmt;
                    DEALLOCATE PREPARE stmt;
                  
                  END
                  $$
                  
                  DELIMITER ;
                  

                  使用方法:

                  SET @fruitArray = '\'apple\',\'banana\'';
                  CALL GetFruits(@fruitArray);
                  

                  这篇关于将数组传递给 MySQL 存储例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 MySQL 中模拟数组变量? 下一篇:Oracle 中的匿名 TABLE 或 VARRAY 类型

                  相关文章

                  最新文章

                • <i id='ip2Mm'><tr id='ip2Mm'><dt id='ip2Mm'><q id='ip2Mm'><span id='ip2Mm'><b id='ip2Mm'><form id='ip2Mm'><ins id='ip2Mm'></ins><ul id='ip2Mm'></ul><sub id='ip2Mm'></sub></form><legend id='ip2Mm'></legend><bdo id='ip2Mm'><pre id='ip2Mm'><center id='ip2Mm'></center></pre></bdo></b><th id='ip2Mm'></th></span></q></dt></tr></i><div id='ip2Mm'><tfoot id='ip2Mm'></tfoot><dl id='ip2Mm'><fieldset id='ip2Mm'></fieldset></dl></div>
                  <legend id='ip2Mm'><style id='ip2Mm'><dir id='ip2Mm'><q id='ip2Mm'></q></dir></style></legend>
                    <bdo id='ip2Mm'></bdo><ul id='ip2Mm'></ul>
                • <tfoot id='ip2Mm'></tfoot>

                    <small id='ip2Mm'></small><noframes id='ip2Mm'>