当前位置:网站首页> 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
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- Judge whether a number is a prime number (prime number)
- 深耕5G,芯讯通持续推动5G应用百花齐放
- SQL injection of cisp-pte (Application of secondary injection)
- [Jianzhi offer] 62 The last remaining number in the circle
- Embedded UC (UNIX System Advanced Programming) -1
- Embedded UC (UNIX System Advanced Programming) -3
- How does the outer disk futures platform distinguish formal security?
- 张平安:加快云上数字创新,共建产业智慧生态
- dried food! Semi supervised pre training dialogue model space
- 干货!半监督预训练对话模型 SPACE
猜你喜欢

【机器人坐标系第一讲】

7.Scala类

Embedded -arm (bare board development) -1

Practical example of propeller easydl: automatic scratch recognition of industrial parts

深潜Kotlin协程(二十一):Flow 生命周期函数

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

ECU introduction

ECU简介

调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%

中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
随机推荐
Embedded-c Language-2
[729. My Schedule i]
Jarvis OJ 简单网管协议
激动人心!2022开放原子全球开源峰会报名火热开启!
C language to get program running time
【性能测试】jmeter+Grafana+influxdb部署实战
Embedded-c Language-1
Application of threshold homomorphic encryption in privacy Computing: Interpretation
Embedded UC (UNIX System Advanced Programming) -3
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
composer安装报错:No composer.lock file present.
[Jianzhi offer] 63 Maximum profit of stock
C# TCP如何限制单个客户端的访问流量
挖财股票开户安全吗?怎么开股票账户是安全?
[first lecture on robot coordinate system]
easyNmon使用汇总
ternary operator
Cs231n notes (bottom) - applicable to 0 Foundation
How does the outer disk futures platform distinguish formal security?
What else do you not know about new map()