{"id":6396,"date":"2024-11-14T11:36:25","date_gmt":"2024-11-14T03:36:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6396\/"},"modified":"2024-11-14T11:36:25","modified_gmt":"2024-11-14T03:36:25","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6396\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u6559\u7a0b"},"content":{"rendered":"<blockquote><p>\n  mysql \u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u7684 sql \u8bed\u53e5\u96c6\u5408\uff0c\u53ef\u4f5c\u4e3a\u5355\u4e2a\u5355\u5143\u6267\u884c\uff0c\u63d0\u4f9b\u63d0\u9ad8\u6027\u80fd\u3001\u4ee3\u7801\u91cd\u7528\u3001\u5b89\u5168\u6027\u3001\u6570\u636e\u5b8c\u6574\u6027\u7b49\u4f18\u52bf\u3002\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u9700\u8981\u786e\u5b9a\u529f\u80fd\u3001\u7f16\u5199\u4ee3\u7801\u3001\u4f7f\u7528 create procedure \u8bed\u53e5\u521b\u5efa\u3001\u4f7f\u7528 call \u8bed\u53e5\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u83b7\u53d6\u7ed9\u5b9a\u5ba2\u6237\u8ba2\u5355\u7684\u5b58\u50a8\u8fc7\u7a0b\uff1acreate procedure get_customer_orders(in customer_id int) begin select * from orders where customer_id = customer_id;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080106401382823.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u6559\u7a0b\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u6559\u7a0b\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u6559\u7a0b<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u5b58\u50a8\u8fc7\u7a0b\uff1f<\/strong><br \/>\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u7684 SQL \u8bed\u53e5\u96c6\u5408\uff0c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4f5c\u4e3a\u5355\u4e2a\u5355\u5143\u6267\u884c\u3002<\/p>\n<p><strong>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<pre>CREATE PROCEDURE procedure_name(\n    -- \u53c2\u6570\u5217\u8868\uff0c\u5982\u679c\u9700\u8981\n)\nBEGIN\n    -- \u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801\nEND<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<pre>CALL procedure_name(\n    -- \u53c2\u6570\u5217\u8868\uff0c\u5982\u679c\u9700\u8981\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f18\u70b9<\/strong><\/p>\n<ul>\n<li>\u63d0\u9ad8\u6027\u80fd\uff1a\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u5728\u6267\u884c\u4e4b\u524d\u5df2\u7531 MySQL \u5206\u6790\u548c\u4f18\u5316\u3002<\/li>\n<li>\u4ee3\u7801\u91cd\u7528\uff1a\u5b58\u50a8\u8fc7\u7a0b\u5141\u8bb8\u60a8\u5c06\u7ecf\u5e38\u4f7f\u7528\u7684 SQL \u4ee3\u7801\u6bb5\u5c01\u88c5\u8d77\u6765\u5e76\u591a\u6b21\u4f7f\u7528\u3002<\/li>\n<li>\u5b89\u5168\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u6388\u4e88\u7279\u5b9a\u7528\u6237\u6743\u9650\uff0c\u4ece\u800c\u9650\u5236\u5bf9\u6570\u636e\u5e93\u7684\u8bbf\u95ee\u3002<\/li>\n<li>\u6570\u636e\u5b8c\u6574\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5305\u542b\u4e1a\u52a1\u903b\u8f91\u548c\u9a8c\u8bc1\u89c4\u5219\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u6b65\u9aa4<\/strong><\/p>\n<ol>\n<li>\u786e\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u7684\u529f\u80fd\u3002<\/li>\n<li>\u7f16\u5199 SQL \u4ee3\u7801\u3002<\/li>\n<li>\u4f7f\u7528 CREATE PROCEDURE \u8bed\u53e5\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u3002<\/li>\n<li>\u4f7f\u7528 CALL \u8bed\u53e5\u6d4b\u8bd5\u5b58\u50a8\u8fc7\u7a0b\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u5b58\u50a8\u8fc7\u7a0b<\/strong><br \/>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a get_customer_orders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8be5\u8fc7\u7a0b\u83b7\u53d6\u7ed9\u5b9a\u5ba2\u6237\u7684\u8ba2\u5355\uff1a<\/p>\n<pre>CREATE PROCEDURE get_customer_orders(\n    IN customer_id INT\n)\nBEGIN\n    SELECT * FROM orders WHERE customer_id = customer_id;\nEND<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u8c03\u7528\u8be5\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/p>\n<pre>CALL get_customer_orders(10);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u6559\u7a0b\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\u9884\u7f16\u8bd1\u7684 sql \u8bed\u53e5\u96c6\u5408\uff0c\u53ef\u4f5c\u4e3a\u5355\u4e2a\u5355\u5143\u6267\u884c\uff0c\u63d0\u4f9b\u63d0\u9ad8\u6027\u80fd\u3001\u4ee3\u7801\u91cd\u7528\u3001\u5b89\u5168\u6027\u3001\u6570\u636e\u5b8c\u6574\u6027\u7b49\u4f18\u52bf\u3002\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u9700\u8981\u786e\u5b9a\u529f\u80fd\u3001\u7f16\u5199\u4ee3\u7801\u3001\u4f7f\u7528 create procedure \u8bed\u53e5\u521b\u5efa\u3001\u4f7f\u7528 call \u8bed\u53e5\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u83b7\u53d6\u7ed9\u5b9a\u5ba2\u6237\u8ba2\u5355\u7684\u5b58\u50a8\u8fc7\u7a0b\uff1acreate procedure get_customer_orders(in customer_id int) begin select * from orders where customer_id = customer_id; MySQL \u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u6559\u7a0b \u4ec0\u4e48\u662f\u5b58\u50a8\u8fc7\u7a0b\uff1f\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u7684 SQL \u8bed\u53e5\u96c6\u5408\uff0c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4f5c\u4e3a\u5355\u4e2a\u5355\u5143\u6267\u884c\u3002 \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b CREATE PROCEDURE procedure_name( &#8212; \u53c2\u6570\u5217\u8868\uff0c\u5982\u679c\u9700\u8981 ) BEGIN &#8212; \u5b58\u50a8\u8fc7\u7a0b\u4ee3\u7801 END \u767b\u5f55\u540e\u590d\u5236 \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b CALL procedure_name( &#8212; \u53c2\u6570\u5217\u8868\uff0c\u5982\u679c\u9700\u8981 ); \u767b\u5f55\u540e\u590d\u5236 \u5b58\u50a8\u8fc7\u7a0b\u7684\u4f18\u70b9 \u63d0\u9ad8\u6027\u80fd\uff1a\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u5728\u6267\u884c\u4e4b\u524d\u5df2\u7531 MySQL \u5206\u6790\u548c\u4f18\u5316\u3002 \u4ee3\u7801\u91cd\u7528\uff1a\u5b58\u50a8\u8fc7\u7a0b\u5141\u8bb8\u60a8\u5c06\u7ecf\u5e38\u4f7f\u7528\u7684 SQL \u4ee3\u7801\u6bb5\u5c01\u88c5\u8d77\u6765\u5e76\u591a\u6b21\u4f7f\u7528\u3002 \u5b89\u5168\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u6388\u4e88\u7279\u5b9a\u7528\u6237\u6743\u9650\uff0c\u4ece\u800c\u9650\u5236\u5bf9\u6570\u636e\u5e93\u7684\u8bbf\u95ee\u3002 \u6570\u636e\u5b8c\u6574\u6027\uff1a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5305\u542b\u4e1a\u52a1\u903b\u8f91\u548c\u9a8c\u8bc1\u89c4\u5219\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\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-6396","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6396","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=6396"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6396\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}