当前位置:网站首页>How MySQL uses JSON_ Extract() takes JSON value
How MySQL uses JSON_ Extract() takes JSON value
2022-07-05 17:14:00 【1024 questions】
mysql take json The value of a key under the string field
1. Use replace() Replace
2. Use JSON_UNQUOTE()
mysql Handle json character string ,JSON_EXTRACT() Extract content
MySQL since 5.7 After that, I started to support json type
mysql take json The value of a key under the string fieldrequirement :mysql edition 5.7 And above
SELECT JSON_EXTRACT('{"uid":"asas02234"}', "$.uid");
because json The key value of is in double quotation marks . So you need to remove the double quotation marks .
1. Use replace() Replaceselect replace(JSON_EXTRACT(infoJson,'$.uid'),'"','') uidfrom users
laravel Use in 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. Use 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 Handle json character string ,JSON_EXTRACT() Extract content MySQL since 5.7 After that, I started to support json type The corresponding analytic function is mainly JSON_EXTRACT():
SELECT JSON_EXTRACT('{"ID":"1"}','$.ID');
Execution results :
JSON_EXTRACT('{"ID":"1"}','$.ID')
"1"
Remove quotation marks and use functions JSON_UNQUOTE():
SELECT JSON_UNQUOTE(JSON_EXTRACT('{"ID":"1"}','$.ID'));
Execution results :
JSON_UNQUOTE(JSON_EXTRACT('{"ID":"1"}','$.ID'))
1
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- 启牛商学院股票开户安全吗?靠谱吗?
- High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
- 阈值同态加密在隐私计算中的应用:解读
- ternary operator
- 7. Scala class
- 2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
- Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?
- 齐宣王典故
- ThoughtWorks global CTO: build the architecture according to needs, and excessive engineering will only "waste people and money"
- 【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
猜你喜欢
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
CMake教程Step1(基本起点)
[729. My schedule I]
CMake教程Step4(安装和测试)
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
ECU简介
国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
dried food! Semi supervised pre training dialogue model space
PHP人才招聘系统开发 源代码 招聘网站源码二次开发
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
随机推荐
Jarvis OJ webshell analysis
Learnopongl notes (II) - Lighting
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
深入理解Redis内存淘汰策略
Timestamp strtotime the day before or after the date
[Jianzhi offer] 66 Build product array
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
Jarvis OJ Telnet Protocol
IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
Embedded -arm (bare board development) -1
ternary operator
[Jianzhi offer] 62 The last remaining number in the circle
Judge whether a string is a full letter sentence
[Jianzhi offer] 63 Maximum profit of stock
【剑指 Offer】66. 构建乘积数组
编译libssh2报错找不到openssl
stirring! 2022 open atom global open source summit registration is hot!
[729. My schedule I]
外盘期货平台如何辨别正规安全?