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)

  • 相关阅读:
    关于技术的学习及批判 人工智能
    爱迪生如何看待手机程序员怎么用移动互联网 人工智能
    量子学习及思考4群体意识 人工智能
    程序员的出路 人工智能
    函数式编程学习之路(14) 人工智能
    量子学习及思考1开篇 人工智能
    函数式编程学习之路(16)图灵完备 人工智能
    开机启动
    动态连接库
    静态常量的问题
  • 原文地址:https://www.cnblogs.com/Struts-pring/p/10948870.html
Copyright © 2011-2022 走看看