是的,您可以使用json_extract()。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Data json -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('{"Name": "John", "CountryName": "US"}');
mysql> insert into DemoTable values('{"Name": "Chris", "CountryName": "UK"}');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----------------------------------------+
| Data                                   |
+----------------------------------------+
| {"Name": "John", "CountryName": "US"}  |
| {"Name": "Chris", "CountryName": "UK"} |
+----------------------------------------+
2 rows in set (0.01 sec)以下是在MySQL Select语句中使用JSON对象中的值的查询-
mysql> SELECT *from DemoTable WHERE json_extract(Data, '$.CountryName') like '%US%';
输出结果
+---------------------------------------+
| Data                                  |
+---------------------------------------+
| {"Name": "John", "CountryName": "US"} |
+---------------------------------------+
1 row in set (0.00 sec)