1、创建函数
-- 创建存储函数 DROP FUNCTION IF EXISTS SPLIT_STR; -- 判断是否存在,存在则删除 CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) DETERMINISTIC BEGIN RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, ‘‘); END;
2、调用方法
SELECT split_str(‘7654,7698,7782,7788‘,‘,‘,1) as one, split_str(‘7654,7698,7782,7788‘,‘,‘,2) as two, split_str(‘7654,7698,7782,7788‘,‘,‘,3) as three, split_str(‘7654,7698,7782,7788‘,‘,‘,4) as forms
原文地址:https://www.cnblogs.com/wuzaipei/p/12663922.html
时间: 2024-10-12 17:24:34