问题描述:
MySQL字符串中提取id数字,例:{“id”:“11111”,“type”:12,“attr”:1}
思路:
1、先将字符串中 “id”:“11111” 提取出来
2、提取11111?
3、这里可以反向思考保留11111,将其他字符去掉
用到两个mysql 函数:
1、SUBSTRING_INDEX
substring_index(str,delim,count)
参数:
str:要处理的字符串
delim:分隔符
count:计数
2、REPLACE
replace (field_name,from_str,to_str)
field_name : 字段名
from_str :需要替换的字符串
to_str :替换成的字符串
解决方案:
SELECT REPLACE(REPLACE(REPLACE(
SUBSTRING_INDEX('{"id":"11111","type":12,"attr":1}',",",1),
'{"id":',''),
'}',''),
'"','') ;