MYSQL内取JSON字符串的长度——关于《mysql存储过程参数为数组或者对象的处理方式》的补充

上一篇文章有这么一段话, 然后通过查文档, 终于查到相产在操作了

参考文档:

    https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-length

     http://www.cnblogs.com/waterystone/p/5626098.html

测试JSON串(相比上一篇的串只是去掉了itemcount字段): 

{"itemlist":[{"regid":0,"iteminfo":{"item_uid":"10441"},"amount":1},{"regid":10,"amount":1}]}

测试的存储过程代码:

CREATE PROCEDURE testJson(IN json_str VARCHAR(4096), OUT itemcount INT)
BEGIN
    DECLARE item_uid VARCHAR(128);
    -- SET itemcount = json_str->>"$.itemcount";
    -- SET info = json_str->>"$.itemlist";
    SET itemcount = JSON_LENGTH(json_str->>"$.itemlist");
END$$

测试结果:

猜你喜欢

转载自blog.csdn.net/scy1028/article/details/85113050