当前位置:网站首页> 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
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- Hiengine: comparable to the local cloud native memory database engine
- IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
- The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
- Error in composer installation: no composer lock file present.
- 【性能测试】全链路压测
- C# TCP如何限制单个客户端的访问流量
- Games101 notes (III)
- 项目引入jar从私服Nexus 拉去遇到的一个问题
- 美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
- How to write a full score project document | acquisition technology
猜你喜欢

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

阈值同态加密在隐私计算中的应用:解读

高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积

NPM installation

Rider 设置选中单词侧边高亮,去除警告建议高亮
![[brush questions] effective Sudoku](/img/5b/3064170bebd1ccbee68d6a85d23830.png)
[brush questions] effective Sudoku

Etcd build a highly available etcd cluster

采用药丸屏的iPhone14或引发中国消费者的热烈抢购

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

URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加
随机推荐
【7.7直播预告】《SaaS云原生应用典型架构》大咖讲师教你轻松构建云原生SaaS化应用,难题一一击破,更有华为周边好礼等你领!
Rider 设置选中单词侧边高亮,去除警告建议高亮
SQL injection of cisp-pte (Application of secondary injection)
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
项目引入jar从私服Nexus 拉去遇到的一个问题
ternary operator
Embedded UC (UNIX System Advanced Programming) -2
【729. 我的日程安排表 I】
[729. My Schedule i]
Is it safe for qiniu business school to open a stock account? Is it reliable?
Cs231n notes (bottom) - applicable to 0 Foundation
国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
Learnopongl notes (I)
Etcd 构建高可用Etcd集群
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
CMake教程Step5(添加系统自检)
【剑指 Offer】63. 股票的最大利润
Writing method of twig array merging
Judge whether a string is a full letter sentence
[brush questions] effective Sudoku