当前位置:网站首页> 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 userslaravel 里使用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
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- 外盘期货平台如何辨别正规安全?
- How does the outer disk futures platform distinguish formal security?
- 挖财股票开户安全吗?怎么开股票账户是安全?
- 调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
- 激动人心!2022开放原子全球开源峰会报名火热开启!
- C how TCP restricts the access traffic of a single client
- Jarvis OJ Flag
- Deep dive kotlin synergy (XXI): flow life cycle function
- 兰空图床苹果快捷指令
- CMake教程Step4(安装和测试)
猜你喜欢

composer安装报错:No composer.lock file present.

Etcd 构建高可用Etcd集群

Embedded -arm (bare board development) -1

First day of learning C language

【729. 我的日程安排表 I】

Embedded -arm (bare board development) -2

Copy mode DMA

Embedded UC (UNIX System Advanced Programming) -3

Hiengine: comparable to the local cloud native memory database engine

Jarvis OJ simple network management protocol
随机推荐
C# TCP如何限制单个客户端的访问流量
Yarn common commands
什么是ROM
Twig数组合并的写法
Etcd 构建高可用Etcd集群
dried food! Semi supervised pre training dialogue model space
拷贝方式之DMA
Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
PHP talent recruitment system development source code recruitment website source code secondary development
微信公众号网页授权登录实现起来如此简单
It is forbidden to copy content JS code on the website page
Copy mode DMA
【性能测试】jmeter+Grafana+influxdb部署实战
网站页面禁止复制内容 JS代码
兰空图床苹果快捷指令
Detailed explanation of printf() and scanf() functions of C language
2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
Iphone14 with pill screen may trigger a rush for Chinese consumers
Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
张平安:加快云上数字创新,共建产业智慧生态