MySQL函数与存储过程字符串长度限制的解决
问题描述
MySQL函数或者存储过程中使用group_concat()函数导致数据字符过长而报错
CREATE DEFINER=`root`@`%` PROCEDURE `get_pipe_child`(IN `in_pipe2Num` varchar(25),IN `in_sectionNum` varchar(5)) BEGIN declare ids varchar(1000) default ''; declare tempids varchar(1000); -- 先根据标段号查询出数据组成临时表 DROP TEMPORARY TABLE IF EXISTS temp_weld_position; CREATE TEMPORARY TABLE temp_weld_position AS select t1.id,t1.section_num,t1.weld_code,t1.lon,t1.lat,t2.pipe1_num,t2.pipe2_num from (select id,section_num,weld_code,lon,lat from weld_position where section_num = in_sectionNum and LENGTH(lon)>=7 and LENGTH(lat)>=6 and is_deleted=0) t1 join (select id,weld_code,pipe1_num,pipe2_num from weld_manage where section_num = in_sectionNum) t2 on t1.weld_code=t2.weld_code; -- 在根据传入的pipe2_num 递归查询出所有的数据,将pipe2_num当做id,pipe1_num当pid set tempids = in_pipe2Num; while tempids is not null do set ids = CONCAT_WS(',',ids,tempids); select GROUP_CONCAT(pipe2_num) into tempids from temp_weld_position where FIND_IN_SET(pipe1_num,tempids)>0; end while; select t1.id,t1.section_num,t1.weld_code,t1.lon,t1.lat,t2.pipe1_num,t2.pipe2_num from (select id,section_num,weld_code,lon,lat from weld_position where section_num = in_sectionNum and LENGTH(lon)>7 and LENGTH(lat)>6 and is_deleted=0) t1 join (select id,weld_code,pipe1_num,pipe2_num from weld_manage where section_num = in_sectionNum) t2 on t1.weld_code=t2.weld_code where FIND_IN_SET(t2.pipe2_num,ids) order by FIND_IN_SET(t2.pipe2_num,ids); END
原因分析:
两个参数ids、tempids定义的varchar(1000),后续执行多次循环,GROUP_CONCAT拼接字符放入这两个参数时就会报字符串长度超限错误,因函数、存储过程中varchar类型最大长度为16383
解决方案:
将varchar(1000)类型变成text或者是BLOB类型解决此问题
到此这篇关于MySQL函数与存储过程字符串长度限制的解决的文章就介绍到这了,更多相关MySQL函数与存储过程字符串长度限制内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Mysql报Table 'mysql.user' doesn't exist问题的解
这篇文章主要给大家介绍了关于Mysql报Table 'mysql.user' doesn't exist问题的解决方法,初学者可能会遇到这个问题,文中通过图文将解决方法介绍的非常详细,需要的朋友可以参考下2022-05-05mysql insert if not exists防止插入重复记录的方法
在 MySQL 中,插入(insert)一条记录很简单,但是一些特殊应用,在插入记录前,需要检查这条记录是否已经存在,只有当记录不存在时才执行插入操作,本文介绍的就是这个问题的解决方案。2011-04-04mysql ERROR 1045 (28000)问题的解决方法
这篇文章主要介绍了mysql ERROR 1045 (28000)问题的解决方法,文中步骤介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2019-10-10
最新评论