mysql查询/修改字段中存储数据(JSON类型)的某个属性的特征

mysql查询/修改字段中存储数据(JSON类型)的某个属性的特征(5.6及以下该字段的类型可能是text类型,其中存储的数据是json数据)。

字段类型:text
mysql 5.6版本及以下(已验证) - 获取存储的json数据中某个属性为0的数据:
select * from police_alarmdetailinfo where AlarmCode = ‘2’ and Extend like ‘%”CLZT”:0%’;

尝试使用5.7及以上的获取方式:
select * from police_alarmdetailinfo pa where pa.Extend ->’$.RecvAlarmDetail.CLZT’=’0’;
则会出现报错:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘>’$.RecvAlarmDetail.CLZT’=’0” at line 1
时间: 0s

注:
对于5.6版本及以下,如果需要使用UPDATE字段中json数据中的某个属性的值,目前只了解到先取该字段数据,然后进行截取处理修改,然后再UPDATE。但是对于5.7版本以上的mysql,好像是可以直接使用UPDATE语句(待验证)

另附:
mysql 5.7及以上(待验证):
select * from police_alarmdetailinfo pa where pa.Extend ->’$.RecvAlarmDetail.CLZT’=’0’;

参考:
https://edu.aliyun.com/a/14904
https://blog.csdn.net/lvchengbo/article/details/52681233

你可能感兴趣的:(MySQL)