{"id":5478,"date":"2024-11-14T13:30:18","date_gmt":"2024-11-14T05:30:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5478\/"},"modified":"2024-11-14T13:30:18","modified_gmt":"2024-11-14T05:30:18","slug":"mysql%e5%be%aa%e7%8e%af%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5478\/","title":{"rendered":"mysql\u5faa\u73af\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u6709\u4e09\u79cd\u5faa\u73af\u65b9\u5f0f\uff1a1. while \u5faa\u73af\uff1a\u6839\u636e\u6761\u4ef6\u6301\u7eed\u6267\u884c\u8bed\u53e5\u5757\uff1b2. repeat \u5faa\u73af\uff1a\u81f3\u5c11\u6267\u884c\u4e00\u6b21\u8bed\u53e5\u5757\uff0c\u7136\u540e\u68c0\u67e5\u6761\u4ef6\uff1b3. loop \u5faa\u73af\uff1a\u65e0\u6761\u4ef6\u5faa\u73af\uff0c\u76f4\u5230\u9047\u5230 end loop \u8bed\u53e5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052903212258306.jpg\" class=\"aligncenter\" title=\"mysql\u5faa\u73af\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"mysql\u5faa\u73af\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5faa\u73af<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\u6267\u884c\u5faa\u73af\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. WHILE \u5faa\u73af<\/strong><\/p>\n<pre>WHILE &lt;\u6761\u4ef6&gt; DO\n  &lt;\u8bed\u53e5\u5757&gt;\nEND WHILE;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\uff1a\u5faa\u73af\u7684\u6761\u4ef6\uff0c\u5f53\u6761\u4ef6\u4e3a TRUE \u65f6\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\u3002<\/li>\n<li>\uff1a\u8981\u5faa\u73af\u6267\u884c\u7684\u8bed\u53e5\u3002<\/li>\n<\/ul>\n<p><strong>2. REPEAT \u5faa\u73af<\/strong><\/p>\n<pre>REPEAT\n  &lt;\u8bed\u53e5\u5757&gt;\nUNTIL &lt;\u6761\u4ef6&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u4e0e WHILE \u5faa\u73af\u7c7b\u4f3c\uff0c\u4f46 REPEAT \u5faa\u73af\u81f3\u5c11\u6267\u884c\u4e00\u6b21\uff0c\u5373\u4f7f \u4e3a FALSE\u3002<\/li>\n<\/ul>\n<p><strong>3. LOOP \u5faa\u73af<\/strong><\/p>\n<pre>LOOP\n  &lt;\u8bed\u53e5\u5757&gt;\nEND LOOP;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u65e0\u6761\u4ef6\u5faa\u73af\uff0c\u76f4\u5230\u9047\u5230 END LOOP \u8bed\u53e5\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u4f7f\u7528 WHILE \u5faa\u73af\u663e\u793a\u4ece 1 \u5230 5 \u7684\u6570\u5b57\uff1a<\/p>\n<pre>SET @i = 1;\nWHILE @i &lt;= 5 DO\n  SELECT @i;\n  SET @i = @i + 1;\nEND WHILE;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5faa\u73af\u6709\u9000\u51fa\u6761\u4ef6\uff0c\u5426\u5219\u5b83\u5c06\u65e0\u9650\u5faa\u73af\u3002<\/li>\n<li>\u4f7f\u7528\u5faa\u73af\u53d8\u91cf (@i \u5728\u793a\u4f8b\u4e2d) \u6765\u8ddf\u8e2a\u5faa\u73af\u72b6\u6001\u3002<\/li>\n<li>\u4f7f\u7528 SET \u8bed\u53e5\u66f4\u65b0\u5faa\u73af\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5faa\u73af\u600e\u4e48\u5199\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>mysql \u4e2d\u6709\u4e09\u79cd\u5faa\u73af\u65b9\u5f0f\uff1a1. while \u5faa\u73af\uff1a\u6839\u636e\u6761\u4ef6\u6301\u7eed\u6267\u884c\u8bed\u53e5\u5757\uff1b2. repeat \u5faa\u73af\uff1a\u81f3\u5c11\u6267\u884c\u4e00\u6b21\u8bed\u53e5\u5757\uff0c\u7136\u540e\u68c0\u67e5\u6761\u4ef6\uff1b3. loop \u5faa\u73af\uff1a\u65e0\u6761\u4ef6\u5faa\u73af\uff0c\u76f4\u5230\u9047\u5230 end loop \u8bed\u53e5\u3002 MySQL \u5faa\u73af \u5728 MySQL \u4e2d\u6267\u884c\u5faa\u73af\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a 1. WHILE \u5faa\u73af WHILE &lt;\u6761\u4ef6&gt; DO &lt;\u8bed\u53e5\u5757&gt; END WHILE; \u767b\u5f55\u540e\u590d\u5236 \uff1a\u5faa\u73af\u7684\u6761\u4ef6\uff0c\u5f53\u6761\u4ef6\u4e3a TRUE \u65f6\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\u3002 \uff1a\u8981\u5faa\u73af\u6267\u884c\u7684\u8bed\u53e5\u3002 2. REPEAT \u5faa\u73af REPEAT &lt;\u8bed\u53e5\u5757&gt; UNTIL &lt;\u6761\u4ef6&gt;; \u767b\u5f55\u540e\u590d\u5236 \u4e0e WHILE \u5faa\u73af\u7c7b\u4f3c\uff0c\u4f46 REPEAT \u5faa\u73af\u81f3\u5c11\u6267\u884c\u4e00\u6b21\uff0c\u5373\u4f7f \u4e3a FALSE\u3002 3. LOOP \u5faa\u73af LOOP &lt;\u8bed\u53e5\u5757&gt; END LOOP; \u767b\u5f55\u540e\u590d\u5236 \u65e0\u6761\u4ef6\u5faa\u73af\uff0c\u76f4\u5230\u9047\u5230 END [&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-5478","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5478","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=5478"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5478\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}