当前位置:网站首页>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 .
边栏推荐
- Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
- 麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
- 手机开证券账户安全吗?怎么买股票详细步骤
- 启牛商学院股票开户安全吗?靠谱吗?
- Jarvis OJ shell traffic analysis
- thinkphp模板的使用
- Little knowledge about C language (array and string)
- WSL2.0安装
- ECU简介
- 【二叉树】根到叶路径上的不足节点
猜你喜欢
随机推荐
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
Use of ThinkPHP template
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
编译libssh2报错找不到openssl
MYSQL group by 有哪些注意事项
兰空图床苹果快捷指令
Practical example of propeller easydl: automatic scratch recognition of industrial parts
It is forbidden to copy content JS code on the website page
Deeply cultivate 5g, and smart core continues to promote 5g applications
Embedded -arm (bare board development) -1
Allusions of King Xuan of Qi Dynasty
通过proc接口调试内核代码
Embedded-c Language-2
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
Jarvis OJ simple network management protocol
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
Embedded UC (UNIX System Advanced Programming) -2
Browser rendering principle and rearrangement and redrawing
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
Judge whether a string is a full letter sentence