当前位置:网站首页>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 userslaravel 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 .
边栏推荐
- Use of ThinkPHP template
- 机器学习编译第2讲:张量程序抽象
- Copy mode DMA
- 通过proc接口调试内核代码
- Little knowledge about C language (array and string)
- Embedded UC (UNIX System Advanced Programming) -1
- 腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
- CMake教程Step4(安装和测试)
- Using C language to realize palindrome number
- Wechat official account web page authorization login is so simple
猜你喜欢
随机推荐
mysql中取出json字段的小技巧
【微信小程序】一文读懂小程序的生命周期和路由跳转
Function sub file writing
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
基于51单片机的电子时钟设计
机器学习02:模型评估
CMake教程Step6(添加自定义命令和生成文件)
Is it safe for qiniu business school to open a stock account? Is it reliable?
麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
PHP talent recruitment system development source code recruitment website source code secondary development
Little knowledge about C language (array and string)
[Jianzhi offer] 66 Build product array
机器学习01:绪论
关于mysql中的json解析函数JSON_EXTRACT
Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
NPM installation
[729. My Schedule i]








