Mysql字符串函数

--获取字符串位置

instr(str,substr) //返回字符串 str 中子字符串的第一个出现位置。

instr("Photo|可爱 毛衣 灿烂","|")  -->6

--截取字符串

substring ( expression , start , length ) 

//substring("Photo|可爱 毛衣 灿烂", 7, 20)  -->可爱 毛衣 灿烂

--替换字符中指定字符

replace('string_expression1' , 'string_expression2' , 'string_expression3')

//replace("可爱 毛衣 灿烂"," ",",") -->可爱,毛衣,灿烂'

--综合使用

select replace(substring("Photo|可爱 毛衣 灿烂",instr("Photo|可爱 毛衣 灿烂","|")+1,length("Photo|可爱 毛衣 灿烂")-instr("Photo|可爱 毛衣 灿烂","|"))," ",",")

-->可爱,毛衣,灿烂