MySQL函數(shù)與存儲過程字符串長度限制的解決
問題描述
MySQL函數(shù)或者存儲過程中使用group_concat()函數(shù)導(dǎo)致數(shù)據(jù)字符過長而報錯
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);?
?
?-- 先根據(jù)標段號查詢出數(shù)據(jù)組成臨時表
?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;
?-- 在根據(jù)傳入的pipe2_num 遞歸查詢出所有的數(shù)據(jù),將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原因分析:
兩個參數(shù)ids、tempids定義的varchar(1000),后續(xù)執(zhí)行多次循環(huán),GROUP_CONCAT拼接字符放入這兩個參數(shù)時就會報字符串長度超限錯誤,因函數(shù)、存儲過程中varchar類型最大長度為16383
解決方案:
將varchar(1000)類型變成text或者是BLOB類型解決此問題
到此這篇關(guān)于MySQL函數(shù)與存儲過程字符串長度限制的解決的文章就介紹到這了,更多相關(guān)MySQL函數(shù)與存儲過程字符串長度限制內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文帶你永久擺脫Mysql時區(qū)錯誤問題(idea數(shù)據(jù)庫可視化插件配置)
在MySQL啟動時會檢查當前系統(tǒng)的時區(qū)并根據(jù)系統(tǒng)時區(qū)設(shè)置全局參數(shù)system_time_zone的值,下面這篇文章主要給大家介紹了關(guān)于如何永久擺脫Mysql時區(qū)錯誤問題(idea數(shù)據(jù)庫可視化插件配置)的相關(guān)資料,需要的朋友可以參考下2022-08-08
mysql?DISTINCT選取多個字段,獲取distinct后的行信息方式
這篇文章主要介紹了mysql?DISTINCT選取多個字段,獲取distinct后的行信息方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01

