CREATE FUNCTION SPLIT_STR(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
delim, '');
#用法:SELECT SPLIT_STR(string, delimiter, position)
#注意position 从1开始
update same_ccc_product set brand_name = SPLIT_STR(product_name,' ',1)
网友评论