当前位置:网站首页> mysql如何使用JSON_EXTRACT()取json值
mysql如何使用JSON_EXTRACT()取json值
2022-07-05 16:42:00 【1024问】
mysql取json字符串字段下的某个键的值
1.使用replace()做替换
2.使用 JSON_UNQUOTE()
mysql处理json字符串,JSON_EXTRACT()提取内容
MySQL自5.7之后开始支持json类型
mysql取json字符串字段下的某个键的值要求:mysql版本5.7及以上
SELECT JSON_EXTRACT('{"uid":"asas02234"}', "$.uid");由于json的键值是带双引号。所以需要去掉双引号。
1.使用replace()做替换select replace(JSON_EXTRACT(infoJson,'$.uid'),'"','') uidfrom userslaravel 里使用JSON_EXTRACT
$applyList = DB::table('invoice') ->select('applied_at','total_amount','invoice_form','invoice_file','reject_reason') ->selectRAW('replace(JSON_EXTRACT(invoice_detail,"$.owner_name"),\'"\',\'\') as owner_name') ->where('uid',Auth::id())->get();2.使用 JSON_UNQUOTE()SELECT JSON_UNQUOTE(JSON_EXTRACT('{"id":"3"}', "$.id"));$applyList = DB::table('invoice') ->select('applied_at','total_amount','invoice_form','invoice_file','reject_reason') ->selectRAW('JSON_UNQUOTE(JSON_EXTRACT(invoice_detail,"$.owner_name")) as owner_name') ->where('uid',Auth::id())->get();mysql处理json字符串,JSON_EXTRACT()提取内容MySQL自5.7之后开始支持json类型相应的解析函数主要是JSON_EXTRACT():
SELECT JSON_EXTRACT('{"ID":"1"}','$.ID');执行结果:
JSON_EXTRACT('{"ID":"1"}','$.ID')
"1"
去除引号使用函数JSON_UNQUOTE():
SELECT JSON_UNQUOTE(JSON_EXTRACT('{"ID":"1"}','$.ID'));执行结果:
JSON_UNQUOTE(JSON_EXTRACT('{"ID":"1"}','$.ID'))
1
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- Keras crash Guide
- ECU introduction
- Embedded UC (UNIX System Advanced Programming) -2
- 張平安:加快雲上數字創新,共建產業智慧生態
- Allusions of King Xuan of Qi Dynasty
- 【729. 我的日程安排表 I】
- [Jianzhi offer] 61 Shunzi in playing cards
- [Web attack and Defense] WAF detection technology map
- Summary of PHP pseudo protocol of cisp-pte
- 飞桨EasyDL实操范例:工业零件划痕自动识别
猜你喜欢

China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users

Embedded-c Language-1

The second day of learning C language for Asian people

The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%

【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试

PHP人才招聘系统开发 源代码 招聘网站源码二次开发

Judge whether a number is a prime number (prime number)

Hiengine: comparable to the local cloud native memory database engine

【性能测试】jmeter+Grafana+influxdb部署实战

【Web攻防】WAF检测技术图谱
随机推荐
Etcd build a highly available etcd cluster
Games101 notes (II)
C# TCP如何设置心跳数据包,才显得优雅呢?
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
The first lesson of EasyX learning
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
Jarvis OJ 简单网管协议
CMake教程Step6(添加自定义命令和生成文件)
一个满分的项目文档是如何书写的|得物技术
張平安:加快雲上數字創新,共建產業智慧生態
[Jianzhi offer] 61 Shunzi in playing cards
Twig数组合并的写法
CMake教程Step5(添加系统自检)
tf. sequence_ Mask function explanation case
Iphone14 with pill screen may trigger a rush for Chinese consumers
Embedded-c Language-3
[61dctf]fm
C# TCP如何限制单个客户端的访问流量
Using C language to realize palindrome number