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

我很清楚,我可以改变参数group_concat_max_len来增加这个限制:

SET SESSION group_concat_max_len = 1000000;

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

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


当前回答

在xampp my.ini配置文件中包含此设置:

[mysqld]
group_concat_max_len = 1000000

然后重启xampp mysql

其他回答

The correct syntax is mysql> SET @@global.group_concat_max_len = integer; If you do not have the privileges to do this on the server where your database resides then use a query like: mySQL="SET @@session.group_concat_max_len = 10000;"or a different value. Next line: SET objRS = objConn.Execute(mySQL)  your variables may be different. then mySQL="SELECT GROUP_CONCAT(......);" etc I use the last version since I do not have the privileges to change the default value of 1024 globally (using cPanel). Hope this helps.

设置最大长度的正确参数是:

SET @@group_concat_max_len = value_numeric;

Value_numeric必须为> 1024;缺省情况下,group_concat_max_len值为1024。

在xampp my.ini配置文件中包含此设置:

[mysqld]
group_concat_max_len = 1000000

然后重启xampp mysql

你可以试试这个

SET GLOBAL group_concat_max_len = 1000000;
SET SESSION group_concat_max_len = 1000000;

是一个临时的会话范围设置。它只适用于当前会话。你应该这样使用它。

SET SESSION group_concat_max_len = 1000000;
select group_concat(column) from table group by column

即使在共享主机中也可以这样做,但当使用其他会话时,需要重复SET session命令。