zoukankan      html  css  js  c++  java
  • mysql 5.7新特新 操作json 数组

    select * from  EDI.edi_history where id = 2577;
    
    UPDATE EDI.edi_history SET response_summary = JSON_REPLACE(response_summary, '$[0].isOverMileStone', 'php') WHERE id = 2577;

    对于json数组,使用$[*]  然后在获取节点.

     


    @Query(value = "select * from EDI.edi_history where json_contains(response_summary, ?1) and json_contains(response_summary, ?2) and json_contains(response_summary, ?3) and json_contains(response_summary, ?4)", nativeQuery = true)
    public List<EdiHistoryDO> findByResponseSummary(String result, String orderNo, String orderId, String docType);


    // UPDATE EDI.edi_history SET response_summary = JSON_REPLACE(response_summary,
    // '$[0].isOverMileStone', 'true')
    // WHERE
    // json_contains(response_summary, '{"courierBillNo":"159900000091"}')
    // and json_contains(response_summary, '{"result":"SUCCESS"}')
    // and response_summary like "%dest_stn%" ;
    @Modifying(clearAutomatically = true)
    //@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
    @Query(value = " UPDATE EDI.edi_history SET response_summary = JSON_REPLACE(response_summary, '$[0].isOverMileStone', ?1) "
    + " WHERE " + " json_contains(response_summary, ?2) "
    + " and json_contains(response_summary, '{"result":"SUCCESS"}') "
    + " and response_summary like "%dest_stn%"", nativeQuery = true)
    public int updateResponseSummaryIsOverMileStoneByCourierBillNo(String trueOrfalse, String courierBillNoJson);


    /**
    * get id from ediHistory which include milestone info
    */
    @Query(value = " select id from EDI.edi_history "
    + " WHERE " + " json_contains(response_summary, ?1) "
    + " and json_contains(response_summary, '{"result":"SUCCESS"}') "
    + " and response_summary like "%dest_stn%"", nativeQuery = true)
    public BigInteger findEdiHistoryId(String courierBillNoJson);

  • 相关阅读:
    SpringCloud Gateway使用实例
    Nacos服务注册与发现
    HashMap源码分析——put方法
    Volatile关键字——内存可见性
    Java的JIT编译器
    why spring?
    mysql 锁
    sql server 表变量和临时表
    mysql 存储过程
    mysql 截取字符串
  • 原文地址:https://www.cnblogs.com/lshan/p/9184924.html
Copyright © 2011-2022 走看看