sql处理字符串: replace替换, substring_index拆分和处理json

时间:2020-06-04 11:18:55   收藏:0   阅读:307

replace

语法:
REPLACE ( string_expression , string_pattern , string_replacement )

参数:

返回类型:

上面都是官话,不好懂!翻成白话:REPLACE(String,from_str,to_str) 即:将String中所有出现的from_str替换为to_str。

substring_index

语法:
substring_index(str, delim, count)

参数:

select SUBSTRING_INDEX(‘mooc_100018252‘,‘_‘,-1); // 结果: 100018252

处理json字段

  1. 获取指定json字符串中指定的属性值,以下三种写法等价:
json_extract(attributes_json,‘$.DP‘) //获取json中指定的值
attributes_json->‘$.DP‘
attributes_json->>‘$.DP‘ //可以有两个尖括号
  1. 去掉查询结果中首尾的双引号:
json_unquote()
如:
select json_unquote(json_extract(attributes_json,‘$.DP‘)) as column_value from t_demand_point where instance_id=2146

原文:https://www.cnblogs.com/linyufeng/p/13041500.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!