当前位置:网站首页> 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 users
laravel 里使用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
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- flask解决CORS ERR 问题
- Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
- 采用药丸屏的iPhone14或引发中国消费者的热烈抢购
- Judge whether a number is a prime number (prime number)
- 网站页面禁止复制内容 JS代码
- The third lesson of EasyX learning
- [729. My schedule I]
- Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
- Twig数组合并的写法
- Allusions of King Xuan of Qi Dynasty
猜你喜欢
Deep learning plus
Jarvis OJ webshell analysis
【机器人坐标系第一讲】
Embedded UC (UNIX System Advanced Programming) -2
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
PHP talent recruitment system development source code recruitment website source code secondary development
[Jianzhi offer] 63 Maximum profit of stock
Games101 notes (II)
Jarvis OJ Telnet Protocol
[729. My Schedule i]
随机推荐
It is forbidden to copy content JS code on the website page
[Jianzhi offer] 62 The last remaining number in the circle
【Web攻防】WAF检测技术图谱
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Jarvis OJ Telnet Protocol
Using C language to realize palindrome number
深耕5G,芯讯通持续推动5G应用百花齐放
启牛商学院股票开户安全吗?靠谱吗?
Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
Judge whether a string is a full letter sentence
How does the outer disk futures platform distinguish formal security?
DenseNet
关于new Map( )还有哪些是你不知道的
【剑指 Offer】61. 扑克牌中的顺子
网站页面禁止复制内容 JS代码
Detailed explanation of printf() and scanf() functions of C language
EasyX second lesson
easyNmon使用汇总
什么是ROM
C how TCP restricts the access traffic of a single client