当前位置:网站首页>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 .
边栏推荐
猜你喜欢
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
Embedded UC (UNIX System Advanced Programming) -3
Embedded UC (UNIX System Advanced Programming) -2
WSL2.0安装
【性能测试】jmeter+Grafana+influxdb部署实战
Browser rendering principle and rearrangement and redrawing
The second day of learning C language for Asian people
thinkphp模板的使用
Three traversal methods of binary tree
随机推荐
ECU简介
C# TCP如何限制单个客户端的访问流量
Wsl2.0 installation
Embedded -arm (bare board development) -1
关于mysql中的json解析函数JSON_EXTRACT
What else do you not know about new map()
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
Error in compiling libssh2. OpenSSL cannot be found
dried food! Semi supervised pre training dialogue model space
【二叉树】根到叶路径上的不足节点
thinkphp3.2.3
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
CMake教程Step1(基本起点)
The first lesson of EasyX learning
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
外盘期货平台如何辨别正规安全?
Embedded UC (UNIX System Advanced Programming) -2
Error in composer installation: no composer lock file present.
中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
深耕5G,芯讯通持续推动5G应用百花齐放