
MySQL 针对JSON类型字段数据进行提取和查询
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
·
前言
请各大网友尊重本人原创知识分享,谨记本人博客:南国以南i、
提示:以下是本篇文章正文内容,下面案例可供参考
背景:
当我们使用SQL查询时,想对数据字段中JOSN串进行特殊处理,以下为简单列举
#使用函数查询:JSON_CONTAINS(字段,JSON_OBJECT('json属性', '内容'))
select JSON_EXTRACT(password, '$.applCde') as applCde,JSON_EXTRACT(password, '$.applyAmt') as applyAmt from user where id='9'
#使用 json字段名->’$.json属性’ 进行查询条
select password->'$.applCde' as applCde,password->'$.applyAmt' as applyAmt from user where id='9'

JSON数据双引号处理
平常的json数据在查询出来的时候 是有双引号的
第一种:
#使用`TRIM函数`去除双引号之后
select TRIM(BOTH '"' FROM JSON_EXTRACT(password, '$.applCde')) as applCde,JSON_EXTRACT(password, '$.applyAmt') as applyAmt from user where id='9'

第二种:
select TRIM(BOTH '"' from `password`->'$.applCde') as num from user WHERE id='9'

第三种:
#通过JSON_UNQUOTE 获取的json数据是不带双引号的
select JSON_UNQUOTE(`password`->'$.applCde') as num FROM user where id='9';

第四种:
select `password`->>'$.applCde' as num from user where id='9'

总结
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
f06604fc
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> 8 天前
d23291ba
* add a ci step for Json_Diagnostic_Positions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* Update ci.cmake to address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typo in the comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typos in ci.cmake
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* invoke the new ci step from ubuntu.yml
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* issue4561 - use diagnostic positions for exceptions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci check failures for unit-diagnostic-postions.cpp
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* improvements based on review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix const correctness string
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* further refinements based on reviews
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add one more test case for full coverage
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* ci check fix - add const
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add unit tests for json_diagnostic_postions only
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_diagnostics
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_build_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
---------
Signed-off-by: Harinath Nampally <harinath922@gmail.com> 9 天前
更多推荐




所有评论(0)