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

        <bdo id='0JlGo'></bdo><ul id='0JlGo'></ul>

      <small id='0JlGo'></small><noframes id='0JlGo'>

    1. <tfoot id='0JlGo'></tfoot>

    2. MySQL 和 GROUP_CONCAT() 最大长度

      时间:2023-08-17
      • <bdo id='I4q4d'></bdo><ul id='I4q4d'></ul>

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

          <tfoot id='I4q4d'></tfoot>
              <legend id='I4q4d'><style id='I4q4d'><dir id='I4q4d'><q id='I4q4d'></q></dir></style></legend>

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

                  <tbody id='I4q4d'></tbody>

              1. 本文介绍了MySQL 和 GROUP_CONCAT() 最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在 MySQL 查询中使用 GROUP_CONCAT() 将多行转换为单个字符串.但是,这个函数的结果的最大长度是1024个字符.

                I'm using GROUP_CONCAT() in a MySQL query to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters.

                我非常清楚我可以更改参数 group_concat_max_len 以增加此限制:

                I'm very well aware that I can change the param group_concat_max_len to increase this limit:

                SET SESSION group_concat_max_len = 1000000;
                

                但是,在我使用的服务器上,我无法更改任何参数.不是通过使用前面的查询,也不是通过编辑任何配置文件.

                However, on the server I'm using, I can't change any param. Not by using the preceding query and not by editing any configuration file.

                所以我的问题是:有没有其他方法可以将多行查询的输出转换为单个字符串?

                So my question is: Is there any other way to get the output of a multiple row query into a single string?

                推荐答案

                CREATE TABLE some_table (
                  field1 int(11) NOT NULL AUTO_INCREMENT,
                  field2 varchar(10) NOT NULL,
                  field3 varchar(10) NOT NULL,
                  PRIMARY KEY (`field1`)
                );
                
                INSERT INTO `some_table` (field1, field2, field3) VALUES
                (1, 'text one', 'foo'),
                (2, 'text two', 'bar'),
                (3, 'text three', 'data'),
                (4, 'text four', 'magic');
                

                这个查询有点奇怪但是它不需要另一个查询来初始化变量;它可以嵌入到更复杂的查询中.它返回所有以分号分隔的field2".

                This query is a bit strange but it does not need another query to initialize the variable; and it can be embedded in a more complex query. It returns all the 'field2's separated by a semicolon.

                SELECT result
                FROM   (SELECT @result := '',
                               (SELECT result
                                FROM   (SELECT @result := CONCAT_WS(';', @result, field2) AS result,
                                               LENGTH(@result)                            AS blength
                                        FROM   some_table
                                        ORDER  BY blength DESC
                                        LIMIT  1) AS sub1) AS result) AS sub2; 
                

                这篇关于MySQL 和 GROUP_CONCAT() 最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:MySQL 错误代码:1175 在 MySQL Workbench 中的 UPDATE 期间 下一篇:如何在 MySQL 的 CONCAT 中使用 GROUP_CONCAT

                相关文章

                最新文章

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

                <tfoot id='wbdhw'></tfoot>
                • <bdo id='wbdhw'></bdo><ul id='wbdhw'></ul>

              3. <small id='wbdhw'></small><noframes id='wbdhw'>