当前位置:网站首页>About JSON parsing function JSON in MySQL_ EXTRACT
About JSON parsing function JSON in MySQL_ EXTRACT
2022-07-05 17:14:00 【1024 questions】
mysql json analytic function JSON_EXTRACT
Example
mysql5.7 json Format and json_extract Method
Data initialization
select sentence
Return result resolution
Usage analysis
mysql json analytic function JSON_EXTRACTMYSQl Its own analytic function JSON_EXTRACT, use JSON_EXTRACT The function parsed by the function will contain double quotation marks
Examplet_table Inside the watch source The fields are represented by json The value written in the format is
{ "info" : { "color" : " white ", "inner_color" : " Beige ", "number" : "12345678", "registration_date" : "2012-11" },"accessory" : [ "1", "4", "5", "6", "7", "8", "9", "10" ],"remark" : " test "}Inquire about color Do not remove the double quotation marks ,inner_color Remove the double quotation marks ,remark Remove double lead
select source->'$.info.color' as color,replace(source->'$.info.inner_color','"','') as inner_color,replace(source->'$.remark','"','') as remark from t_tableQuery results
| “ white ” | Beige | test |
json_test Table data ,id and jsonstr Field ( type json)
{ "no": "7", "title": " The way of exercise ", "content": [{ "text": " Your usual exercise and time ", "item1": [{ "text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected" }, { "text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected" }], "item2": [{ "text": " jogging 222 Combination of walking and running ", "type": "text", "value": " jogging 2" }, { "text": " Up and down stairs / Climbing the mountain 2", "type": "number", "value": "33" }] }]}select sentence SELECT id, json_extract( t.jsonstr, '$.*' ), json_extract( t.jsonstr, '$.title' ) AS "title", json_extract( t.jsonstr, '$.content' ) AS "content" , json_extract( t.jsonstr, '$**.text' ) AS "text" , json_extract( t.jsonstr, '$.content[*].item1[*]' ) AS "item1" FROM json_test t; Return result resolution //json_extract( t.jsonstr, '$.*' ) return :["7", " The way of exercise ", [{"text": " Your usual exercise and time ", "item1": [{"text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected"}, {"text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected"}], "item2": [{"text": " jogging 222 Combination of walking and running ", "type": "text", "value": " jogging 2"}, {"text": " Up and down stairs / Climbing the mountain 2", "type": "number", "value": "33"}]}]]//json_extract( t.jsonstr, '$.title' ) AS "title" return :" The way of exercise "//json_extract( t.jsonstr, '$.content' ) AS "content" return :[{"text": " Your usual exercise and time ", "item1": [{"text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected"}, {"text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected"}], "item2": [{"text": " jogging 222 Combination of walking and running ", "type": "text", "value": " jogging 2"}, {"text": " Up and down stairs / Climbing the mountain 2", "type": "number", "value": "33"}]}]//json_extract( t.jsonstr, '$**.text' ) AS "text" return :[" Your usual exercise and time ", " jogging / Step on it / Combination of walking and running ", " Up and down stairs / Climbing the mountain ", " jogging 222 Combination of walking and running ", " Up and down stairs / Climbing the mountain 2"]//json_extract( t.jsonstr, '$.content[*].item1[*]' ) AS "item1" return :[{"text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected"}, {"text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected"}] Usage analysis | ‘$.*’ | Return to all json |
| ‘$.title’ | return key=”title” The data of |
| ‘$**.text’ | Return to all the lowest levels key=”text” The data of |
| ‘$.content[*].item1[*]’ | return key=content Of list Of key=item1 Of list All of |
Official documents :https://dev.mysql.com/doc/refman/5.7/en/json.html
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
猜你喜欢
![[729. My Schedule i]](/img/e3/32914227d00cf7595ee850e60f2b72.png)
[729. My Schedule i]

干货!半监督预训练对话模型 SPACE

The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale

ternary operator

Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city

WSL2.0安装

Deeply cultivate 5g, and smart core continues to promote 5g applications

【729. 我的日程安排錶 I】

First day of learning C language

Practical example of propeller easydl: automatic scratch recognition of industrial parts
随机推荐
Function sub file writing
云安全日报220705:红帽PHP解释器发现执行任意代码漏洞,需要尽快升级
Embedded-c Language-5
Iphone14 with pill screen may trigger a rush for Chinese consumers
张平安:加快云上数字创新,共建产业智慧生态
深入理解Redis内存淘汰策略
Three traversal methods of binary tree
mysql如何使用JSON_EXTRACT()取json值
Timestamp strtotime the day before or after the date
WSL2.0安装
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
【二叉树】根到叶路径上的不足节点
Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?
2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
Embedded-c Language-3
Use of ThinkPHP template
Twig数组合并的写法
阈值同态加密在隐私计算中的应用:解读
CMake教程Step6(添加自定义命令和生成文件)
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body