更新?是插入动作吧?还是说已经存在记录了?
--------------下面的字段对应应该没错吧?
system对应jobtype
company_id对应cid
installer_id对应installerid
installer_config_id对应configid
追问就是从tjob_task表中查询出json_data字段,再把这个字段分解,分解后的字符再更新到tjob_task中,后面的四个字段是后加的!
追答你最好把思路理清了再说。你这么心急,连我提出的疑问都没一个个回答清楚,我是无法帮你的。
追问额,这么说吧,最终是更新!需求就是从从tjob_task表中查询出json_data字段,
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/d50735fae6cd7b89ca7e813f0d2442a7d9330e7f?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
json_data是已经存在的记录,
取出json_data中的四个字符,再更新到tjob_task表中的四个字段中,这四个字段之前是null
追答 --先创建一个取json数据的方法
CREATE function `get_json_data`(
jsonstr VARCHAR(100),
keystr VARCHAR(20)
)
RETURNS VARCHAR(50)
BEGIN
declare cnt int default 0;
declare i int default 0;
declare tempKeyStr varchar(100);
DECLARE tempstr varchar(100);
set jsonstr=REPLACE(jsonstr,'{','');
set jsonstr=REPLACE(jsonstr,'}','');
set jsonstr=REPLACE(jsonstr,'"','');
while length(jsonstr)>0
do
set tempstr= SUBSTRING_INDEX(jsonstr,',',1);
set tempKeyStr = SUBSTRING_INDEX(tempstr,':',1);
if (tempKeyStr=keystr) then
RETURN SUBSTR(tempstr,LENGTH(SUBSTRING_INDEX(tempstr,':',1))+2);
end if;
set jsonstr = SUBSTR(jsonstr,LENGTH(tempstr)+2);
end while;
RETURN '';
END;
--再做update语句
update `job_task` set
system=get_json_data(json_data,'jobtype')
,
company_id=get_json_data(json_data,'cid')
,
installer_id=get_json_data(json_data,'installerid')
,
installer_config_id=get_json_data(json_data,'configid')来自:求助得到的回答