zoukankan      html  css  js  c++  java
  • 通过json_set函数,来修改data字段的值

    SELECT REPLACE(json_extract(param,'$.payFundAcc'),'"','') from t_external_trade_event where status != 'S' ;

    mysql> update tab_json set data = json_set(data,"$.address","Guangzhou") where id = 1; #对id = 1的行的address的键值进行修改.
    Query OK, 1 row affected (0.26 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from tab_json;
    +----+--------------------------------------------------------------+
    | id | data |
    +----+--------------------------------------------------------------+
    | 1 | {"tel": 13249872314, "name": "Mike", "address": "Guangzhou"} |
    | 2 | {"tel": 189776542, "name": "David", "address": "Shanghai"} |
    +----+--------------------------------------------------------------+
    rows in set (0.00 sec)

    mysql> update tab_json set data = json_set(data,"$.address","Shenzhen");
    Query OK, 2 rows affected (0.02 sec)
    Rows matched: 2 Changed: 2 Warnings: 0

    mysql> select * from tab_json;
    +----+-------------------------------------------------------------+
    | id | data |
    +----+-------------------------------------------------------------+
    | 1 | {"tel": 13249872314, "name": "Mike", "address": "Shenzhen"} |
    | 2 | {"tel": 189776542, "name": "David", "address": "Shenzhen"} |
    +----+-------------------------------------------------------------+
    rows in set (0.00 sec)

    mysql> update tab_json set data = json_set(data,"$.address","Hangzhou") where id = 2; #对id为2的address键值进行修改
    Query OK, 1 row affected (0.03 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from tab_json;
    +----+-------------------------------------------------------------+
    | id | data |
    +----+-------------------------------------------------------------+
    | 1 | {"tel": 13249872314, "name": "Mike", "address": "Shenzhen"} |
    | 2 | {"tel": 189776542, "name": "David", "address": "Hangzhou"} |
    +----+-------------------------------------------------------------+
    rows in set (0.00 sec)

    mysql> update tab_json set data = json_set(data,"$.passcode","654567") where id = 1; #对id为1的passcode字段进行修改,发现没有这个键值,就增加了一个键值对.
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from tab_json;
    +----+-----------------------------------------------------------------------------------+
    | id | data |
    +----+-----------------------------------------------------------------------------------+
    | 1 | {"tel": 13249872314, "name": "Mike", "address": "Shenzhen", "passcode": "654567"} |
    | 2 | {"tel": 189776542, "name": "David", "address": "Hangzhou"} |
    +----+-----------------------------------------------------------------------------------+
    rows in set (0.00 sec)

    mysql> update tab_json set data = json_set(data,"$.olds","12") where id = 2;
    Query OK, 1 row affected (0.17 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from tab_json;
    +----+-----------------------------------------------------------------------------------+
    | id | data |
    +----+-----------------------------------------------------------------------------------+
    | 1 | {"tel": 13249872314, "name": "Mike", "address": "Shenzhen", "passcode": "654567"} |
    | 2 | {"tel": 189776542, "name": "David", "olds": "12", "address": "Hangzhou"} |
    +----+-----------------------------------------------------------------------------------+
    rows in set (0.00 sec)

    mysql> update tab_json set data = json_set(data,"$.age","33");
    Query OK, 2 rows affected (0.02 sec)
    Rows matched: 2 Changed: 2 Warnings: 0

    mysql> select * from tab_json;
    +----+------------------------------------------------------------------------------------------------+
    | id | data |
    +----+------------------------------------------------------------------------------------------------+
    | 1 | {"age": "33", "tel": 13249872314, "name": "Mike", "address": "Shenzhen", "passcode": "654567"} |
    | 2 | {"age": "33", "tel": 189776542, "name": "David", "olds": "12", "address": "Hangzhou"} |
    +----+------------------------------------------------------------------------------------------------+
    rows in set (0.00 sec)

  • 相关阅读:
    SpringBlade 端口占用 Web server failed to start. Port 80 was already in use.
    SpringBlade 找不到或无法加载主类 springboot.Application
    Java idea 常用快捷键
    Java Velocity
    个人 一些需求
    Java MyBatis-Plus 基本使用
    Java Spring Initializr 创建的项目 包是一层一层的,需要隐藏一下空包
    MapReduce之自定义OutputFormat
    数据链路层之PPP协议
    MapReduce之GroupingComparator分组(辅助排序、二次排序)
  • 原文地址:https://www.cnblogs.com/Struts-pring/p/10948870.html
Copyright © 2011-2022 走看看