MySQL 的 xml 和 json 支持

-- 测试 MySQL 5.6 MySQL 8.0 通过
create table xml(
	id int not null auto_increment,
	xml varchar(255) not null,
	primary key(id)
);

insert into xml(xml) values('<sucess>100</sucess>');
insert into xml(xml) values('<sucess>100</sucess><failure>200</failure>');

select id, extractvalue(xml, 'sucess') as sucess from xml;

+----+--------+
| id | sucess |
+----+--------+
|  1 | 100    |
|  2 | 100    |
+----+--------+
1 row in set (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     |
+----+--------+---------+
2 rows in set (0.00 sec)

-- 测试 MySQL 8.0 通过
create table json(
	id int not null auto_increment,
	json varchar(255) not null,
	primary key(id)
);


insert into json(json) values('{"name": "Alice", "sex": "female", "age": 23}');
insert into 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   |
+---------+----------+------+
2 rows in set (0.00 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值