可以使用以下函數
SUBSTRING_INDEX( i.final_car_type, ' ', 1 )
i.final_car_type 即需要分隔的字串
’ ’ 即以空格分隔該字串
如果count 是1
DELIMITER $$ CREATE DEFINER=`root`@`%` PROCEDURE `proc_split_Id`(in selectIds blob(65535), in splitChar varchar(2)) BEGIN set @i=0; CREATE TEMPORARY TABLE if not exists Id_Result_s(Id long NOT NULL); truncate table Id_Result_s; SET @cnt = 1+(LENGTH(selectIds) - LENGTH(REPLACE(selectIds,splitChar,''))); set @i=1; start transaction; WHILE @i <=@cnt DO SET @result = REPLACE(SUBSTRING(SUBSTRING_INDEX(selectIds, splitChar, @i), LENGTH(SUBSTRING_INDEX(selectIds, splitChar, @i -1)) + 1), splitChar, ''); INSERT INTO Id_Result_s(Id) VALUES (@result ); SET @i = @i + 1; END WHILE; commit; END###selectIds為需要拆分的字串,splitChar為分隔符號. 拆分的結果保存在臨時表Id_Result_s中.######while中有insert語句,循環插入.在while前後加上start transaction和commit可以提高效率.# ##
以上是MySQL怎麼用分隔符號分隔字串的詳細內容。更多資訊請關注PHP中文網其他相關文章!