MySQL函數(shù)與存儲(chǔ)過(guò)程字符串長(zhǎng)度限制的解決
問(wèn)題描述
MySQL函數(shù)或者存儲(chǔ)過(guò)程中使用group_concat()函數(shù)導(dǎo)致數(shù)據(jù)字符過(guò)長(zhǎng)而報(bào)錯(cuò)
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)段號(hào)查詢(xún)出數(shù)據(jù)組成臨時(shí)表
?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 遞歸查詢(xún)出所有的數(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原因分析:
兩個(gè)參數(shù)ids、tempids定義的varchar(1000),后續(xù)執(zhí)行多次循環(huán),GROUP_CONCAT拼接字符放入這兩個(gè)參數(shù)時(shí)就會(huì)報(bào)字符串長(zhǎng)度超限錯(cuò)誤,因函數(shù)、存儲(chǔ)過(guò)程中varchar類(lèi)型最大長(zhǎng)度為16383
解決方案:
將varchar(1000)類(lèi)型變成text或者是BLOB類(lèi)型解決此問(wèn)題
到此這篇關(guān)于MySQL函數(shù)與存儲(chǔ)過(guò)程字符串長(zhǎng)度限制的解決的文章就介紹到這了,更多相關(guān)MySQL函數(shù)與存儲(chǔ)過(guò)程字符串長(zhǎng)度限制內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mysql inner join on的用法實(shí)例(必看)
下面小編就為大家?guī)?lái)一篇Mysql inner join on的用法實(shí)例(必看)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03
一文帶你永久擺脫Mysql時(shí)區(qū)錯(cuò)誤問(wèn)題(idea數(shù)據(jù)庫(kù)可視化插件配置)
在MySQL啟動(dòng)時(shí)會(huì)檢查當(dāng)前系統(tǒng)的時(shí)區(qū)并根據(jù)系統(tǒng)時(shí)區(qū)設(shè)置全局參數(shù)system_time_zone的值,下面這篇文章主要給大家介紹了關(guān)于如何永久擺脫Mysql時(shí)區(qū)錯(cuò)誤問(wèn)題(idea數(shù)據(jù)庫(kù)可視化插件配置)的相關(guān)資料,需要的朋友可以參考下2022-08-08
mysql?DISTINCT選取多個(gè)字段,獲取distinct后的行信息方式
這篇文章主要介紹了mysql?DISTINCT選取多個(gè)字段,獲取distinct后的行信息方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
淺談MySQL的B樹(shù)索引與索引優(yōu)化小結(jié)
這篇文章主要介紹了淺談MySQL的B樹(shù)索引與索引優(yōu)化小結(jié),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03

