zoukankan      html  css  js  c++  java
  • mysql json_extract函数获取json字段中某个key的值

    json_extract函数可以获取json对象中指定key的值,用法:json_extract(json_filed,"$.key")
    举例1:
    mysql> select json_extract('{"name":"Zhaim","tel":"13240133388"}',"$.tel");
    +--------------------------------------------------------------+
    | json_extract('{"name":"Zhaim","tel":"13240133388"}',"$.tel") |
    +--------------------------------------------------------------+
    | "13240133388"                                                |
    +--------------------------------------------------------------+
    1 row in set (0.00 sec)
    举例2:
    mysql> select * from tab_json;
    +----+----------------------------------------------------------------+
    | id | data                                                           |
    +----+----------------------------------------------------------------+
    |  1 | {"Tel": "132223232444", "name": "david", "address": "Beijing"} |
    |  2 | {"Tel": "13390989765", "name": "Mike", "address": "Guangzhou"} |
    +----+----------------------------------------------------------------+
    2 rows in set (0.00 sec)
     
    mysql> select json_extract(data,'$.name') from tab_json;
    +-----------------------------+
    | json_extract(data,'$.name') |
    +-----------------------------+
    | "david" |
    | "Mike" |
    +-----------------------------+
    2 rows in set (0.00 sec)

    如果查询没有的key,那么是可以查询,不过返回的是NULL。

    mysql> select json_extract(data,'$.name'),json_extract(data,'$.tel') from tab_json;
    +-----------------------------+----------------------------+
    | json_extract(data,'$.name') | json_extract(data,'$.tel') |
    +-----------------------------+----------------------------+
    | "david" | NULL |
    | "Mike" | NULL |
    +-----------------------------+----------------------------+
    2 rows in set (0.00 sec)

  • 相关阅读:
    BUG漏测的原因总结,以及如何处理
    费用流
    拉格朗日插值
    数论问题整理
    计数问题
    POJ 1741 Tree
    bzoj 2820: YY的GCD
    luogu P3690 【模板】Link Cut Tree (动态树)
    bzoj 1036: [ZJOI2008]树的统计Count
    bzoj 3282: Tree
  • 原文地址:https://www.cnblogs.com/mianbaoshu/p/14036505.html
Copyright © 2011-2022 走看看