当前位置:网站首页> 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
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
猜你喜欢

Browser rendering principle and rearrangement and redrawing

兰空图床苹果快捷指令

High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body

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

IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
![[729. My Schedule i]](/img/e3/32914227d00cf7595ee850e60f2b72.png)
[729. My Schedule i]

Embedded-c Language-2

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

Copy mode DMA

腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
随机推荐
Embedded-c Language-3
Hiengine: comparable to the local cloud native memory database engine
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
Iphone14 with pill screen may trigger a rush for Chinese consumers
stirring! 2022 open atom global open source summit registration is hot!
[Jianzhi offer] 62 The last remaining number in the circle
Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
CMake教程Step3(添加库的使用要求)
7.Scala类
thinkphp3.2.3
PHP人才招聘系统开发 源代码 招聘网站源码二次开发
启牛商学院股票开户安全吗?靠谱吗?
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
C# TCP如何设置心跳数据包,才显得优雅呢?
浏览器渲染原理以及重排与重绘
Is it safe for qiniu business school to open a stock account? Is it reliable?
Combined use of vant popup+ other components and pit avoidance Guide
Embedded-c Language-2
Using C language to realize palindrome number