The group_concat () function data used in MySQL is intercepted (with the default length limit). Exercise caution !, Mysqlgroup_concat

Source: Internet
Author: User

The group_concat () function data used in MySQL is intercepted (with the default length limit). Exercise caution !, Mysqlgroup_concat

Recently encountered a problem at work:

Some of our system's logic processing is implemented by the storage process. However, one day our Customer Service reported that the order was not placed, and we checked the basic product resources involved in the order.

There are two codes in the stored procedure of placing an order:

1   declare _err int default 0;2   DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND set _err=1;3   DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' set _err=2; 

After the stored procedure is executed, Variable _ err will return 1. You can only debug the stored procedure to find the problem. When debugging the following section, it is found that after the SQL statement is executed, _ err is changed to 1.

1 select group_concat(concat(@room_name,',',run_date,',',total_count) separator '|') into @order_desc from tmp_order_detail order by run_date;    

Because the temporary table tmp_order_detail contains a large amount of data, I guess it is a problem with group_concat. So I reduced the data in the temporary table by half and found that it was successful. So I guess group_concat has a length limit, google, sure enough.

For the group_concat function:

Group_concat is okay when the data volume is small, but there is a problem when the data volume hits

Group_concat: the default connectable length is 1024. If the maximum length has been set, it will be truncated to this length;

When group_concat is used in a select statement, the limit statement becomes invalid;

Solution:

1,Modify the MySQL configuration file:

# Length group_concat_max_len = 5120

 

2. You can also use SQL statement settings:

SET GLOBAL group_concat_max_len=5120;SET SESSION group_concat_max_len=5120;

I used the second method in the stored procedure to execute the stored procedure. OK, success!

 

Off duty (today is Sunday )!!!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.