{"id":7630,"date":"2024-11-14T10:27:24","date_gmt":"2024-11-14T02:27:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7630\/"},"modified":"2024-11-14T10:27:24","modified_gmt":"2024-11-14T02:27:24","slug":"mysql-%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e6%9b%bf%e6%8d%a2-json-%e5%86%85%e5%ae%b9%e6%97%b6%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bc%9a%e5%87%ba%e7%8e%b0%e5%a4%a7%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7630\/","title":{"rendered":"MySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5185\u5bb9\u65f6\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u7684\u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173106407570484.jpg\" class=\"aligncenter\" title=\"MySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5185\u5bb9\u65f6\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u7684\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"MySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5185\u5bb9\u65f6\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u7684\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362json\u5185\u5bb9\u9047\u5230\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u4e00\u4f4d\u5f00\u53d1\u8005\u5728\u4f7f\u7528mysql\u5b58\u50a8\u8fc7\u7a0b\u65f6\u9047\u5230\u4e86\u95ee\u9898\uff0c\u65e0\u6cd5\u66ff\u6362json\u5185\u5bb9\u5e76\u663e\u793a\u66ff\u6362\u540e\u7684\u6587\u672c\u3002\u95ee\u9898\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>delimiter \/\/\ndrop procedure if exists `replacename`\/\/\ncreate procedure replacename()\n\nbegin \ndeclare c int default 0;\ndeclare r json ;\ndeclare id int default 0;\ndeclare i int default 0;\n\ndeclare result cursor for select id,slider_image from `eb_store_product`;\n\nselect count(*) into c from eb_store_product;\nopen  result;\n\nrepeat \n    set i = i + 1;\n    fetch result into id,r;\n\n    set @t = replace(json_extract(r,'$[0]'),'ceshi','chenggong');\n\nuntil i &gt;= c\nend repeat; \nclose result;\nselect @t;\n\nend\/\/\n\ncall replacename();\/\/\ndelimiter ;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd0\u884c\u8be5\u4ee3\u7801\u540e\uff0c\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u9519\u8bef\u63d0\u793a\uff1a<\/p>\n<blockquote><p>\n  \u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u3002\n<\/p><\/blockquote>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u95ee\u9898\u51fa\u73b0\u5728\u4ee3\u7801\u4e2d\u7f3a\u5c11\u5bf9eb_store_product\u8868\u4e2dslider_image\u5b57\u6bb5\u7684\u66f4\u65b0\u3002\u4fee\u6539\u540e\u7684\u6b63\u786e\u4ee3\u7801\u5982\u4e0b\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>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e86update\u8bed\u53e5\uff0c\u7528\u4e8e\u66f4\u65b0eb_store_product\u8868\u4e2d\u5bf9\u5e94\u884c\u7684slider_image\u5b57\u6bb5\uff0c\u4ece\u800c\u89e3\u51b3\u4e86\u66ff\u6362json\u5185\u5bb9\u540e\u65e0\u6cd5\u663e\u793a\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362 JSON \u5185\u5bb9\u65f6\uff0c\u4f1a\u51fa\u73b0\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\u7684\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362json\u5185\u5bb9\u9047\u5230\u7684\u95ee\u9898 \u4e00\u4f4d\u5f00\u53d1\u8005\u5728\u4f7f\u7528mysql\u5b58\u50a8\u8fc7\u7a0b\u65f6\u9047\u5230\u4e86\u95ee\u9898\uff0c\u65e0\u6cd5\u66ff\u6362json\u5185\u5bb9\u5e76\u663e\u793a\u66ff\u6362\u540e\u7684\u6587\u672c\u3002\u95ee\u9898\u4ee3\u7801\u5982\u4e0b\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 from `eb_store_product`; select count(*) into c from eb_store_product; open result; repeat set i = i + 1; [&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-7630","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7630","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=7630"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7630\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}