修改JSON对象里的值
要求:
JSON对象为 yyyy/m/d hh:mm:ss
转化为 yyyy-mm-dd
核心函数:
JSON_EXTRACT(content, '$.writeDate') 获取JSON对象content属性中key为writeDate的值
JSON_SET(content, '$.writeDate', "值") 将JSON对象content属性中key为writeDate的值修改
SUBSTRING_INDEX("a/b/c","/",1) 拆分字符串
UPDATE business_jcxx_qiaoliang_kpxx
set content = JSON_SET(content, '$.writeDate',
concat(
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',0+1),'/',-1),'"',-1),"-",
if(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',1+1),'/',-1)<10,
concat("0",SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',1+1),'/',-1)),
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',1+1),'/',-1)),"-",
if(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',2+1),'/',-1)<10,
concat("0",SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',2+1),'/',-1)),
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(content, '$.writeDate'),' ',1),'/',2+1),'/',-1))
)
)
修改数组对象里的值
要求:
JSON对象为 yyyy-mm-dd hh:mm:ss
转化为 yyyy-mm-dd
核心函数:
JSON_EXTRACT(content, '$[0].writeDate') 获取数组对象content属性中第一项key为writeDate的值
JSON_SET(content, '$[0].writeDate', "值") 将数组对象content属性中第一项key为writeDate的值修改
SUBSTRING_INDEX("a/b/c","/",1) 拆分字符串
UPDATE business_jcxx_qiaoliang_kpxx
set yhczjlList = JSON_SET(yhczjlList,'$[0].beginDate',
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(yhczjlList,'$[0].beginDate'),' ',1),'/',0+1),'/',-1),'"',-1)
),
yhczjlList = JSON_SET(yhczjlList,'$[0].endDate',
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_EXTRACT(yhczjlList,'$[0].endDate'),' ',1),'/',0+1),'/',-1),'"',-1)
)