-- 测试 MySQL 5.6 MySQL 8.0 通过createtable xml(
id intnotnullauto_increment,
xml varchar(255)notnull,primarykey(id));insertinto xml(xml)values('<sucess>100</sucess>');insertinto xml(xml)values('<sucess>100</sucess><failure>200</failure>');select id, extractvalue(xml,'sucess')as sucess from xml;+----+--------+| id | sucess |+----+--------+|1|100||2|100|+----+--------+1rowinset(0.00 sec)select id, extractvalue(xml,'sucess')as sucess, extractvalue(xml,'failure')as failure from xml;+----+--------+---------+| id | sucess | failure |+----+--------+---------+|1|100|||2|100|200|+----+--------+---------+2rowsinset(0.00 sec)
-- 测试 MySQL 8.0 通过createtable json(
id intnotnullauto_increment,
json varchar(255)notnull,primarykey(id));insertinto json(json)values('{"name": "Alice", "sex": "female", "age": 23}');insertinto json(json)values('{"name": "Bob", "sex": "male", "age": 20}');select json_extract(json,'$.name')as name, json_extract(json,'$.sex')as sex, json_extract(json,'$.age')as age from json;+---------+----------+------+| name | sex | age |+---------+----------+------+|"Alice"|"female"|23||"Bob"|"male"|20|+---------+----------+------+2rowsinset(0.00 sec)