zoukankan      html  css  js  c++  java
  • mysql中json_extract函数的使用?作用是什么?

    http://www.cnblogs.com/chuanzhang053/p/9139624.html

    需求描述:

      今天看mysql中的json数据类型,涉及到一些使用,使用到了函数json_extract来

      获取json字段中某个key的值,在此记录下.

    操作过程:

    |  2 | {"Tel": "13390989765", "name": "Mike", "address": "Guangzhou"} |
    +----+----------------------------------------------------------------+
    2 rows in set (0.00 sec)

    复制代码

    备注:data字段就是json的数据类型,由键值对组成.

    复制代码

    备注:这个查询时直接对json对象进行操作.

    3.对tab_json表使用json_extract函数

    复制代码
    mysql> select json_extract(data,'$.name') from tab_json;
    +-----------------------------+
    | json_extract(data,'$.name') |
    +-----------------------------+
    | "david"                     |
    | "Mike"                      |
    +-----------------------------+
    2 rows in set (0.00 sec)
    
    mysql> select json_extract(data,'$.name'),json_extract(data,'$.tel') from tab_json;  #如果查询没有的key,那么是可以查询,不过返回的是NULL.
    +-----------------------------+----------------------------+
    | json_extract(data,'$.name') | json_extract(data,'$.tel') |
    +-----------------------------+----------------------------+
    | "david"                     | NULL                       |
    | "Mike"                      | NULL                       |
    +-----------------------------+----------------------------+
    2 rows in set (0.00 sec)
    
    mysql> select json_extract(data,'$.name'),json_extract(data,'$.address') from tab_json;
    +-----------------------------+--------------------------------+
    | json_extract(data,'$.name') | json_extract(data,'$.address') |
    +-----------------------------+--------------------------------+
    | "david"                     | "Beijing"                      |
    | "Mike"                      | "Guangzhou"                    |
    +-----------------------------+--------------------------------+
    2 rows in set (0.00 sec)
    复制代码

    备注:通过json_extract函数,获取到了json对象的特定key的值.

  • 相关阅读:
    【CF1043C】Smallest Word(构造)
    【CF1043B】Lost Array(枚举)
    【CF1043A】Elections(签到)
    【Codeforces Round #519】
    【HDOJ5556】Land of Farms(最大团)
    【HDOJ1828&&POJ1177】Picture(线段树,扫描线)
    【SPOJ61】Brackets(线段树)
    lgy -oracle
    虚拟机软件VMware Workstation Pro的安装与使用
    [技巧] 解决Win7下VMware中vmx86.sys报错的问题
  • 原文地址:https://www.cnblogs.com/fengff/p/9293558.html
Copyright © 2011-2022 走看看