{"id":6237,"date":"2024-11-14T11:18:24","date_gmt":"2024-11-14T03:18:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6237\/"},"modified":"2024-11-14T11:18:24","modified_gmt":"2024-11-14T03:18:24","slug":"mysql%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%a6%82%e4%bd%95%e6%89%a7%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6237\/","title":{"rendered":"mysql\u5b58\u50a8\u8fc7\u7a0b\u5982\u4f55\u6267\u884c"},"content":{"rendered":"<blockquote><p>\n  \u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u5148\u7f16\u8bd1\u7684 mysql \u67e5\u8be2\u96c6\u5408\uff0c\u7528\u4e8e\u6267\u884c\u590d\u6742\u4e8b\u52a1\u3002\u6b65\u9aa4\uff1a1. \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff08create procedure\uff09\uff1b2. \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff08call\uff09\u3002\u597d\u5904\uff1a1. \u6027\u80fd\u63d0\u5347\uff1b2. \u53ef\u7ef4\u62a4\u6027\u589e\u5f3a\uff1b3. \u7f51\u7edc\u6d41\u91cf\u51cf\u5c11\uff1b4. \u5b89\u5168\u6027\u589e\u5f3a\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061515422852754.jpg\" class=\"aligncenter\" title=\"mysql\u5b58\u50a8\u8fc7\u7a0b\u5982\u4f55\u6267\u884c\u63d2\u56fe\" alt=\"mysql\u5b58\u50a8\u8fc7\u7a0b\u5982\u4f55\u6267\u884c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6267\u884c MySQL \u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u662f MySQL \u4e2d\u9884\u5148\u7f16\u8bd1\u7684\u67e5\u8be2\u7684\u96c6\u5408\uff0c\u5141\u8bb8\u5bf9\u6574\u4e2a\u4e8b\u52a1\u8fdb\u884c\u590d\u6742\u7684\u5904\u7406\u3002\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong>\u4f7f\u7528 CREATE PROCEDURE \u8bed\u53e5\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6307\u5b9a\u5176\u540d\u79f0\u3001\u53c2\u6570\uff08\u5982\u679c\u9700\u8981\uff09\u548c\u4ee3\u7801\u4f53\u3002<\/li>\n<li> <strong>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong>\u4f7f\u7528 CALL \u8bed\u53e5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6307\u5b9a\u5176\u540d\u79f0\u548c\u53c2\u6570\u503c\uff08\u5982\u679c\u9700\u8981\uff09\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>CREATE PROCEDURE get_customer_orders(IN customer_id INT)\nBEGIN\n   SELECT * FROM orders WHERE customer_id = customer_id;\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>CALL get_customer_orders(10);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u7684\u6240\u6709\u53c2\u6570\u90fd\u5fc5\u987b\u63d0\u4f9b\u503c\uff0c\u5426\u5219\u4f1a\u5f15\u53d1\u9519\u8bef\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u7ed3\u679c\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528 SELECT&#8230;INTO \u8bed\u53e5\u68c0\u7d22\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u4fee\u6539\u6570\u636e\u5e93\u6570\u636e\uff0c\u56e0\u6b64\u5728\u8c03\u7528\u4e4b\u524d\u5e94\u5ba1\u9605\u5176\u4ee3\u7801\u4ee5\u786e\u4fdd\u5176\u9884\u671f\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<p><strong>\u597d\u5904\uff1a<\/strong><\/p>\n<ul>\n<li>\u63d0\u9ad8\u6027\u80fd\uff1a\u5b58\u50a8\u8fc7\u7a0b\u7ecf\u8fc7\u9884\u7f16\u8bd1\uff0c\u56e0\u6b64\u6267\u884c\u901f\u5ea6\u6bd4\u52a8\u6001 SQL \u67e5\u8be2\u66f4\u5feb\u3002<\/li>\n<li>\u63d0\u9ad8\u53ef\u7ef4\u62a4\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u5c06\u590d\u6742\u67e5\u8be2\u903b\u8f91\u5c01\u88c5\u5728\u4e00\u4e2a\u5730\u65b9\uff0c\u4fbf\u4e8e\u7ef4\u62a4\u548c\u66f4\u6539\u3002<\/li>\n<li>\u51cf\u5c11\u7f51\u7edc\u6d41\u91cf\uff1a\u5b58\u50a8\u8fc7\u7a0b\u5c06\u67e5\u8be2\u548c\u6570\u636e\u4fee\u6539\u53d1\u9001\u5230\u6570\u636e\u5e93\u4f5c\u4e3a\u5355\u4e00\u8bf7\u6c42\uff0c\u51cf\u5c11\u4e86\u7f51\u7edc\u6d41\u91cf\u3002<\/li>\n<li>\u589e\u5f3a\u5b89\u5168\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ea\u80fd\u7531\u5177\u6709\u9002\u5f53\u6743\u9650\u7684\u7528\u6237\u6267\u884c\uff0c\u4ece\u800c\u589e\u5f3a\u4e86\u5bf9\u7684\u5b89\u5168\u6027\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b58\u50a8\u8fc7\u7a0b\u5982\u4f55\u6267\u884c\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\u662f\u9884\u5148\u7f16\u8bd1\u7684 mysql \u67e5\u8be2\u96c6\u5408\uff0c\u7528\u4e8e\u6267\u884c\u590d\u6742\u4e8b\u52a1\u3002\u6b65\u9aa4\uff1a1. \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff08create procedure\uff09\uff1b2. \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff08call\uff09\u3002\u597d\u5904\uff1a1. \u6027\u80fd\u63d0\u5347\uff1b2. \u53ef\u7ef4\u62a4\u6027\u589e\u5f3a\uff1b3. \u7f51\u7edc\u6d41\u91cf\u51cf\u5c11\uff1b4. \u5b89\u5168\u6027\u589e\u5f3a\u3002 \u5982\u4f55\u6267\u884c MySQL \u5b58\u50a8\u8fc7\u7a0b \u5b58\u50a8\u8fc7\u7a0b\u662f MySQL \u4e2d\u9884\u5148\u7f16\u8bd1\u7684\u67e5\u8be2\u7684\u96c6\u5408\uff0c\u5141\u8bb8\u5bf9\u6574\u4e2a\u4e8b\u52a1\u8fdb\u884c\u590d\u6742\u7684\u5904\u7406\u3002\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u7ef4\u62a4\u6027\u3002 \u6b65\u9aa4\uff1a \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff1a\u4f7f\u7528 CREATE PROCEDURE \u8bed\u53e5\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6307\u5b9a\u5176\u540d\u79f0\u3001\u53c2\u6570\uff08\u5982\u679c\u9700\u8981\uff09\u548c\u4ee3\u7801\u4f53\u3002 \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a\u4f7f\u7528 CALL \u8bed\u53e5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6307\u5b9a\u5176\u540d\u79f0\u548c\u53c2\u6570\u503c\uff08\u5982\u679c\u9700\u8981\uff09\u3002 \u793a\u4f8b\uff1a CREATE PROCEDURE get_customer_orders(IN customer_id INT) BEGIN SELECT * FROM orders WHERE customer_id = customer_id; END; \u767b\u5f55\u540e\u590d\u5236 CALL get_customer_orders(10); \u767b\u5f55\u540e\u590d\u5236 \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u7684\u6240\u6709\u53c2\u6570\u90fd\u5fc5\u987b\u63d0\u4f9b\u503c\uff0c\u5426\u5219\u4f1a\u5f15\u53d1\u9519\u8bef\u3002 \u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u7ed3\u679c\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528 SELECT&#8230;INTO \u8bed\u53e5\u68c0\u7d22\u3002 \u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u4fee\u6539\u6570\u636e\u5e93\u6570\u636e\uff0c\u56e0\u6b64\u5728\u8c03\u7528\u4e4b\u524d\u5e94\u5ba1\u9605\u5176\u4ee3\u7801\u4ee5\u786e\u4fdd\u5176\u9884\u671f\u884c\u4e3a\u3002 \u597d\u5904\uff1a \u63d0\u9ad8\u6027\u80fd\uff1a\u5b58\u50a8\u8fc7\u7a0b\u7ecf\u8fc7\u9884\u7f16\u8bd1\uff0c\u56e0\u6b64\u6267\u884c\u901f\u5ea6\u6bd4\u52a8\u6001 SQL \u67e5\u8be2\u66f4\u5feb\u3002 \u63d0\u9ad8\u53ef\u7ef4\u62a4\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u5c06\u590d\u6742\u67e5\u8be2\u903b\u8f91\u5c01\u88c5\u5728\u4e00\u4e2a\u5730\u65b9\uff0c\u4fbf\u4e8e\u7ef4\u62a4\u548c\u66f4\u6539\u3002 [&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-6237","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6237","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=6237"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6237\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}