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ù)標(biāo)段號查詢出數(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當(dāng)做id,pipe1_num當(dāng)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報Table?'mysql.user'?doesn't?exist問題的解
這篇文章主要給大家介紹了關(guān)于Mysql報Table?'mysql.user'?doesn't?exist問題的解決方法,初學(xué)者可能會遇到這個問題,文中通過圖文將解決方法介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05
MySQL實(shí)現(xiàn)查詢數(shù)據(jù)庫表記錄數(shù)
這篇文章主要介紹了MySQL實(shí)現(xiàn)查詢數(shù)據(jù)庫表記錄數(shù),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09
mysql insert if not exists防止插入重復(fù)記錄的方法
在 MySQL 中,插入(insert)一條記錄很簡單,但是一些特殊應(yīng)用,在插入記錄前,需要檢查這條記錄是否已經(jīng)存在,只有當(dāng)記錄不存在時才執(zhí)行插入操作,本文介紹的就是這個問題的解決方案。2011-04-04
mysql ERROR 1045 (28000)問題的解決方法
這篇文章主要介紹了mysql ERROR 1045 (28000)問題的解決方法,文中步驟介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-10-10

