mysql中有个字段是数组形式的,想更新其中某个的值,其他值不变。

此表为体检表,表名为h1 , 表中有字段身份证号card 以及数组形式的具体体检信息, 想修改其中的体检日期date ,其他信息不变,有什么好的办法。

先取出里面的内容,修改完成后再更新到数据表里面。

Table 12.20 JSON Functions
Name Description
JSON_ARRAY() Create JSON array
JSON_ARRAY_APPEND() Append data to JSON document
JSON_ARRAY_INSERT() Insert into JSON array
-> Return value from JSON column after evaluating path;
equivalent to JSON_EXTRACT().
JSON_CONTAINS() Whether JSON document contains specific object at path
Functions That Create JSON Values
1795
Name Description
JSON_CONTAINS_PATH() Whether JSON document contains any data at path
JSON_DEPTH() Maximum depth of JSON document
JSON_EXTRACT() Return data from JSON document
->> Return value from JSON column after evaluating
path and unquoting the result; equivalent to
JSON_UNQUOTE(JSON_EXTRACT()).
JSON_INSERT() Insert data into JSON document
JSON_KEYS() Array of keys from JSON document
JSON_LENGTH() Number of elements in JSON document
JSON_MERGE() (deprecated 8.0.3) Merge JSON documents, preserving duplicate keys.
Deprecated synonym for JSON_MERGE_PRESERVE()
JSON_MERGE_PATCH() Merge JSON documents, replacing values of duplicate keys
JSON_MERGE_PRESERVE() Merge JSON documents, preserving duplicate keys
JSON_OBJECT() Create JSON object
JSON_PRETTY() Prints a JSON document in human-readable format, with
each array element or object member printed on a new line,
indented two spaces with respect to its parent.
JSON_QUOTE() Quote JSON document
JSON_REMOVE() Remove data from JSON document
JSON_REPLACE() Replace values in JSON document
JSON_SEARCH() Path to value within JSON document
JSON_SET() Insert data into JSON document
JSON_STORAGE_FREE() Freed space within binary representation of a JSON column
value following a partial update
JSON_STORAGE_SIZE() Space used for storage of binary representation of a JSON
document; for a JSON column, the space used when the
document was inserted, prior to any partial updates
JSON_TABLE() Returns data from a JSON expression as a relational table
JSON_TYPE() Type of JSON value
JSON_UNQUOTE() Unquote JSON value
JSON_VALID() Whether JSON value is valid

解决了,用以下方法即可,json_replace
UPDATE table
SET lie = json_replace(lie, '$.shuzuzhi', '2021-09-01')
WHERE card=''
table表名,lie列名,shuzuzhi数组里面要修改名称,2021-09-01要修改为的值。