1. 程式人生 > >mysql group_concat方法的應用

mysql group_concat方法的應用

做專案時,經常有需求將一列資料合併為字串的需求,一般可以將資料查詢出來以後可以使用連線方法進行拼接字串。 mysql 有個函式可以很好的解決  group_concat。 1、 group_concat 是將分組後的某列資料合併在一起,用法 : group_concat(column separator  '_'), 預設是‘,’連線。 2、 group_concat 是有長度限制的。預設是1024。可以通過以下方法設定長度。 在資料庫中設定長度:(重啟資料庫後無效) show variables like "group_concat_max_len"; 
  SET GLOBAL group_concat_max_len=102400;    SET SESSION group_concat_max_len=102400;

mysql配置檔案

my.ini檔案加入[mysqld] 下面加入引數配置

group_concat_max_len = 200000

設定為-1就為最大值

group_concat_max_len = -1