{"id":26598,"date":"2024-11-24T15:29:58","date_gmt":"2024-11-24T07:29:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26598\/"},"modified":"2024-11-24T15:29:58","modified_gmt":"2024-11-24T07:29:58","slug":"mysql-%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e6%9b%bf%e6%8d%a2-json-%e5%ad%97%e6%ae%b5%e6%96%87%e6%9c%ac%e5%a4%b1%e8%b4%a5%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e5%a4%a7%e5%ad%97-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26598\/","title":{"rendered":"MySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5b57\u6bb5\u6587\u672c\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173102599224615.jpg\" class=\"aligncenter\" title=\"MySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5b57\u6bb5\u6587\u672c\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"MySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5b57\u6bb5\u6587\u672c\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 json \u5b57\u6bb5\u4e2d\u6587\u672c\u5931\u8d25\uff0c\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u9047\u5230 mysql \u5b58\u50a8\u8fc7\u7a0b\u4e2d\uff0c\u5c1d\u8bd5\u66ff\u6362 json \u5b57\u6bb5\u4e2d\u6587\u672c\u65f6\u51fa\u73b0\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u9519\u8bef\uff0c\u8ba9\u6211\u4eec\u63a2\u7d22\u95ee\u9898\u5e76\u627e\u51fa\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u95ee\u9898\u6839\u6e90\u5728\u4e8e\uff0c\u539f\u59cb\u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801\u5e76\u672a\u66f4\u65b0 eb_store_product \u8868\u4e2d\u8981\u66ff\u6362\u503c\u7684 slider_image \u5b57\u6bb5\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u4fee\u6539\u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801\uff0c\u5728\u6bcf\u6b21\u66ff\u6362\u6587\u672c\u540e\u6267\u884c update \u8bed\u53e5\u4ee5\u66f4\u65b0 slider_image \u5b57\u6bb5\uff1a<\/p>\n<pre>DELIMITER \/\/\nDROP PROCEDURE IF EXISTS `replacename`\/\/\nCREATE PROCEDURE replacename()\nBEGIN\n    DECLARE c INT DEFAULT 0;\n    DECLARE r JSON;\n    DECLARE id INT DEFAULT 0;\n    DECLARE i INT DEFAULT 0;\n\n    DECLARE result CURSOR FOR SELECT id, slider_image FROM `eb_store_product`;\n\n    SELECT COUNT(*) INTO c FROM eb_store_product;\n    OPEN result;\n\n    REPEAT\n        SET i = i + 1;\n        FETCH result INTO id, r;\n\n        SET @t = REPLACE(JSON_EXTRACT(r, '$[0]'), 'ceshi', 'chenggong');\n\n        -- \u66f4\u65b0 eb_store_product \u8868\u4e2d\u7684 slider_image \u5b57\u6bb5\n        UPDATE eb_store_product SET slider_image = JSON_REPLACE(r, '$[0]', @t) WHERE id = id;\n\n    UNTIL i &gt;= c\n    END REPEAT;\n\n    CLOSE result;\n    SELECT @t;\nEND\/\/\nDELIMITER ;\n\nCALL replacename();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u6267\u884c\u4e0a\u8ff0\u66f4\u65b0\u540e\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u4f60\u73b0\u5728\u5e94\u8be5\u80fd\u591f\u6210\u529f\u66ff\u6362 json \u5b57\u6bb5\u4e2d\u7684\u6587\u672c\uff0c\u5e76\u83b7\u5f97\u66ff\u6362\u540e\u7684\u6587\u672c\u800c\u4e0d\u4f1a\u51fa\u73b0\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5b57\u6bb5\u6587\u672c\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 json \u5b57\u6bb5\u4e2d\u6587\u672c\u5931\u8d25\uff0c\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6cd5 \u9047\u5230 mysql \u5b58\u50a8\u8fc7\u7a0b\u4e2d\uff0c\u5c1d\u8bd5\u66ff\u6362 json \u5b57\u6bb5\u4e2d\u6587\u672c\u65f6\u51fa\u73b0\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u9519\u8bef\uff0c\u8ba9\u6211\u4eec\u63a2\u7d22\u95ee\u9898\u5e76\u627e\u51fa\u89e3\u51b3\u65b9\u6848\u3002 \u95ee\u9898\u6839\u6e90\u5728\u4e8e\uff0c\u539f\u59cb\u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801\u5e76\u672a\u66f4\u65b0 eb_store_product \u8868\u4e2d\u8981\u66ff\u6362\u503c\u7684 slider_image \u5b57\u6bb5\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u4fee\u6539\u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801\uff0c\u5728\u6bcf\u6b21\u66ff\u6362\u6587\u672c\u540e\u6267\u884c update \u8bed\u53e5\u4ee5\u66f4\u65b0 slider_image \u5b57\u6bb5\uff1a DELIMITER \/\/ DROP PROCEDURE IF EXISTS `replacename`\/\/ CREATE PROCEDURE replacename() BEGIN DECLARE c INT DEFAULT 0; DECLARE r JSON; DECLARE id INT DEFAULT 0; DECLARE i INT DEFAULT 0; DECLARE result CURSOR FOR SELECT id, slider_image [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26598","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26598"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26598\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}