{"id":6592,"date":"2024-11-14T09:04:31","date_gmt":"2024-11-14T01:04:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6592\/"},"modified":"2024-11-14T09:04:31","modified_gmt":"2024-11-14T01:04:31","slug":"mysql%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%86%99%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6592\/","title":{"rendered":"mysql\u5b58\u50a8\u8fc7\u7a0b\u5199\u6cd5"},"content":{"rendered":"<blockquote><p>\n  mysql \u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u79cd\u9884\u7f16\u8bd1\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u5728 mysql \u6570\u636e\u5e93\u4e2d\u6267\u884c\u590d\u6742\u7684\u64cd\u4f5c\u3002\u5176\u4f18\u70b9\u5305\u62ec\uff1a\u6027\u80fd\u4f18\u5316\u3001\u4ee3\u7801\u91cd\u7528\u3001\u589e\u5f3a\u5b89\u5168\u6027\u3001\u4e8b\u52a1\u652f\u6301\u3002\u521b\u5efa mysql \u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\u4e3a\uff1acreate procedure procedure_name (parameter_list); \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\u4e3a\uff1acall procedure_name (argument_list); \u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/06\/2024080618424541135.jpg\" class=\"aligncenter\" title=\"mysql\u5b58\u50a8\u8fc7\u7a0b\u5199\u6cd5\u63d2\u56fe\" alt=\"mysql\u5b58\u50a8\u8fc7\u7a0b\u5199\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1f<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u79cd\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u9884\u7f16\u8bd1\u548c\u5b58\u50a8\u7684\u4ee3\u7801\u5757\uff0c\u5b83\u5141\u8bb8\u4e00\u6b21\u6027\u6267\u884c\u590d\u6742\u7684\u64cd\u4f5c\u96c6\u5408\u3002\u5b83\u662f\u4e00\u79cd\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u88ab\u591a\u6b21\u8c03\u7528\u7684\u7528\u6237\u5b9a\u4e49\u7684\u7a0b\u5e8f\u3002<\/p>\n<p><strong>\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u6027\u80fd\u4f18\u5316\uff1a<\/strong>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u7f16\u8bd1\u4e00\u6b21\uff0c\u7136\u540e\u5728\u9700\u8981\u65f6\u91cd\u590d\u6267\u884c\u3002<\/li>\n<li> <strong>\u4ee3\u7801\u91cd\u7528\uff1a<\/strong>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5c06\u7ecf\u5e38\u4f7f\u7528\u7684\u4ee3\u7801\u7247\u6bb5\u5c01\u88c5\u8d77\u6765\uff0c\u4ee5\u4fbf\u5728\u4e0d\u540c\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u91cd\u590d\u4f7f\u7528\u3002<\/li>\n<li> <strong>\u589e\u5f3a\u5b89\u5168\u6027\uff1a<\/strong>\u5b58\u50a8\u8fc7\u7a0b\u63d0\u4f9b\u4e86\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u5e93\u6570\u636e\u7684\u5b89\u5168\u65b9\u5f0f\u3002<\/li>\n<li> <strong>\u4e8b\u52a1\u652f\u6301\uff1a<\/strong>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5305\u542b\u4e8b\u52a1\uff0c\u4ee5\u786e\u4fdd\u64cd\u4f5c\u8981\u4e48\u5168\u90e8\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u521b\u5efa MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u521b\u5efa MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1a<\/p>\n<pre>CREATE PROCEDURE procedure_name (parameter_list)\nBEGIN\n    -- \u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801\nEND<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a get_customer_orders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b83\u83b7\u53d6\u6307\u5b9a\u5ba2\u6237\u7684\u6240\u6709\u8ba2\u5355\uff1a<\/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<p><strong>\u8c03\u7528 MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8c03\u7528 MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1a<\/p>\n<pre>CALL procedure_name (argument_list);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8c03\u7528 get_customer_orders \u5b58\u50a8\u8fc7\u7a0b\uff0c\u5e76\u83b7\u53d6\u5ba2\u6237 ID \u4e3a 1 \u7684\u6240\u6709\u8ba2\u5355\uff1a<\/p>\n<pre>CALL get_customer_orders(1);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\u5fc5\u987b\u552f\u4e00\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5305\u542b\u4e34\u65f6\u53d8\u91cf\u3001\u63a7\u5236\u6d41\u8bed\u53e5\u548c\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b58\u50a8\u8fc7\u7a0b\u5199\u6cd5\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 \u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u79cd\u9884\u7f16\u8bd1\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u5728 mysql \u6570\u636e\u5e93\u4e2d\u6267\u884c\u590d\u6742\u7684\u64cd\u4f5c\u3002\u5176\u4f18\u70b9\u5305\u62ec\uff1a\u6027\u80fd\u4f18\u5316\u3001\u4ee3\u7801\u91cd\u7528\u3001\u589e\u5f3a\u5b89\u5168\u6027\u3001\u4e8b\u52a1\u652f\u6301\u3002\u521b\u5efa mysql \u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\u4e3a\uff1acreate procedure procedure_name (parameter_list); \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\u4e3a\uff1acall procedure_name (argument_list); \u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002 MySQL \u5b58\u50a8\u8fc7\u7a0b \u4ec0\u4e48\u662f MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1f \u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u79cd\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u9884\u7f16\u8bd1\u548c\u5b58\u50a8\u7684\u4ee3\u7801\u5757\uff0c\u5b83\u5141\u8bb8\u4e00\u6b21\u6027\u6267\u884c\u590d\u6742\u7684\u64cd\u4f5c\u96c6\u5408\u3002\u5b83\u662f\u4e00\u79cd\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u88ab\u591a\u6b21\u8c03\u7528\u7684\u7528\u6237\u5b9a\u4e49\u7684\u7a0b\u5e8f\u3002 \u5b58\u50a8\u8fc7\u7a0b\u7684\u4f18\u70b9\uff1a \u6027\u80fd\u4f18\u5316\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u7f16\u8bd1\u4e00\u6b21\uff0c\u7136\u540e\u5728\u9700\u8981\u65f6\u91cd\u590d\u6267\u884c\u3002 \u4ee3\u7801\u91cd\u7528\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5c06\u7ecf\u5e38\u4f7f\u7528\u7684\u4ee3\u7801\u7247\u6bb5\u5c01\u88c5\u8d77\u6765\uff0c\u4ee5\u4fbf\u5728\u4e0d\u540c\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u91cd\u590d\u4f7f\u7528\u3002 \u589e\u5f3a\u5b89\u5168\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u63d0\u4f9b\u4e86\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u5e93\u6570\u636e\u7684\u5b89\u5168\u65b9\u5f0f\u3002 \u4e8b\u52a1\u652f\u6301\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5305\u542b\u4e8b\u52a1\uff0c\u4ee5\u786e\u4fdd\u64cd\u4f5c\u8981\u4e48\u5168\u90e8\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u3002 \u5982\u4f55\u521b\u5efa MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1a \u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u521b\u5efa MySQL \u5b58\u50a8\u8fc7\u7a0b\uff1a CREATE PROCEDURE procedure_name (parameter_list) BEGIN &#8212; \u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801 END \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a get_customer_orders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b83\u83b7\u53d6\u6307\u5b9a\u5ba2\u6237\u7684\u6240\u6709\u8ba2\u5355\uff1a CREATE PROCEDURE get_customer_orders (IN customer_id INT) BEGIN SELECT * FROM [&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-6592","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6592","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=6592"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6592\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}