{"id":26754,"date":"2024-11-24T15:53:02","date_gmt":"2024-11-24T07:53:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26754\/"},"modified":"2024-11-24T15:53:02","modified_gmt":"2024-11-24T07:53:02","slug":"mysql-%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e4%b8%ad%e6%9b%bf%e6%8d%a2%e6%95%b0%e7%bb%84%e6%96%87%e6%9c%ac%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e6%8f%90%e7%a4%ba%e5%a4%a7%e5%ad%97%e6%ae%b5-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26754\/","title":{"rendered":"MySQL \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u66ff\u6362\u6570\u7ec4\u6587\u672c\uff0c\u4e3a\u4ec0\u4e48\u63d0\u793a\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173105892310596.jpg\" class=\"aligncenter\" title=\"MySQL \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u66ff\u6362\u6570\u7ec4\u6587\u672c\uff0c\u4e3a\u4ec0\u4e48\u63d0\u793a\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\uff1f\u63d2\u56fe\" alt=\"MySQL \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u66ff\u6362\u6570\u7ec4\u6587\u672c\uff0c\u4e3a\u4ec0\u4e48\u63d0\u793a\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u66ff\u6362\u6570\u7ec4\u6587\u672c\u51fa\u9519\uff1f<\/strong><\/p>\n<p>\u5728\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362\u6570\u7ec4\u6587\u672c\u65f6\u9047\u5230\u95ee\u9898\uff0c\u63d0\u793a&#8221;\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728&#8221;\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u7528\u4e8e\u4ece eb_store_product \u8868\u4e2d\u63d0\u53d6\u6570\u7ec4\u6587\u672c\u5e76\u66ff\u6362\u90e8\u5206\u5185\u5bb9\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    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>\u7136\u800c\uff0c\u6267\u884c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u8fd4\u56de &#8220;\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728&#8221; \u7684\u9519\u8bef\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4ee3\u7801\u4e2d\u7f3a\u5c11\u66f4\u65b0 eb_store_product \u8868\u4e2d slider_image \u5b57\u6bb5\u7684\u6b65\u9aa4\u3002\u9700\u8981\u5728\u5faa\u73af\u4f53\u5185\u6dfb\u52a0\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>update eb_store_product set slider_image = json_replace(r, '$[0]', @t) where id = id;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u662f\u4fee\u6539\u540e\u7684\u5b58\u50a8\u8fc7\u7a0b\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>\u4ee5\u4e0a\u5c31\u662fMySQL \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u66ff\u6362\u6570\u7ec4\u6587\u672c\uff0c\u63d0\u793a\u201c\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728\u201d\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\u4e2d\u66ff\u6362\u6570\u7ec4\u6587\u672c\u51fa\u9519\uff1f \u5728\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u66ff\u6362\u6570\u7ec4\u6587\u672c\u65f6\u9047\u5230\u95ee\u9898\uff0c\u63d0\u793a&#8221;\u5927\u5b57\u6bb5\u4fe1\u606f\u4e0d\u5b58\u5728&#8221;\u3002 \u4ee5\u4e0b\u4ee3\u7801\u7528\u4e8e\u4ece eb_store_product \u8868\u4e2d\u63d0\u53d6\u6570\u7ec4\u6587\u672c\u5e76\u66ff\u6362\u90e8\u5206\u5185\u5bb9\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 = [&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-26754","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26754","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=26754"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26754\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}