{"id":5253,"date":"2024-11-14T11:11:36","date_gmt":"2024-11-14T03:11:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5253\/"},"modified":"2024-11-14T11:11:36","modified_gmt":"2024-11-14T03:11:36","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5253\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b"},"content":{"rendered":"<blockquote><p>\n  mysql \u5b58\u50a8\u8fc7\u7a0b\u662f\u5b58\u50a8\u7684\u4e00\u7ec4 transact-sql \u8bed\u53e5\uff0c\u53ef\u6309\u9700\u8c03\u7528\uff0c\u7528\u4e8e\u5c01\u88c5\u76f8\u5173\u4ee3\u7801\u5757\u3002\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1. \u4f7f\u7528 create procedure \u8bed\u53e5\uff1b2. \u5b9a\u4e49\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\uff1b3. \u7f16\u5199\u5305\u542b transact-sql \u8bed\u53e5\u7684\u5b58\u50a8\u8fc7\u7a0b\u4f53\uff1b4. \u4f7f\u7528 end \u5173\u952e\u5b57\u7ed3\u675f\u5b58\u50a8\u8fc7\u7a0b\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052617370510996.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5b9a\u4e49 MySQL \u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<p><strong>\u5b9a\u4e49\uff1a<\/strong><br \/>\u5b58\u50a8\u8fc7\u7a0b\u662f MySQL \u4e2d\u5b58\u50a8\u7684\u4e00\u7ec4 Transact-SQL (T-SQL) \u8bed\u53e5\uff0c\u4ee5\u4fbf\u5728\u9700\u8981\u65f6\u88ab\u8c03\u7528\u3002\u5b83\u662f\u4e00\u79cd\u5c06\u76f8\u5173\u4ee3\u7801\u5757\u5c01\u88c5\u6210\u4e00\u4e2a\u72ec\u7acb\u5355\u5143\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u9700\u8981\u65f6\u9ad8\u6548\u5730\u6267\u884c\u3002<\/p>\n<p><strong>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><strong>1. \u4f7f\u7528 CREATE PROCEDURE \u8bed\u53e5<\/strong><\/p>\n<pre>CREATE PROCEDURE procedure_name (\n    -- \u53c2\u6570\u5b9a\u4e49\n)\nLANGUAGE SQL\n-- \u5b58\u50a8\u8fc7\u7a0b\u4f53\nBEGIN\n    -- \u4ee3\u7801\u8bed\u53e5\nEND<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5b9a\u4e49\u53c2\u6570<\/strong><br \/>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5177\u6709\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002\u5728 CREATE PROCEDURE \u8bed\u53e5\u4e2d\u4f7f\u7528 IN\u3001OUT \u6216 INOUT \u5173\u952e\u5b57\u6307\u5b9a\u53c2\u6570\u7c7b\u578b\u3002<\/p>\n<p><strong>3. \u7f16\u5199\u5b58\u50a8\u8fc7\u7a0b\u4f53<\/strong><br \/>\u5b58\u50a8\u8fc7\u7a0b\u4f53\u5305\u542b\u9700\u8981\u6267\u884c\u7684 Transact-SQL \u8bed\u53e5\u3002\u5b83\u53ef\u4ee5\u5305\u62ec\u53d8\u91cf\u58f0\u660e\u3001\u6761\u4ef6\u8bed\u53e5\u3001\u5faa\u73af\u548c\u6570\u636e\u64cd\u4f5c\u3002<\/p>\n<p><strong>4. \u7ed3\u675f\u5b58\u50a8\u8fc7\u7a0b<\/strong><br \/>\u4f7f\u7528 END \u5173\u952e\u5b57\u7ed3\u675f\u5b58\u50a8\u8fc7\u7a0b\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><br \/>\u4ee5\u4e0b\u793a\u4f8b\u521b\u5efa\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u6765\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u7684\u548c\uff1a<\/p>\n<pre>CREATE PROCEDURE add_numbers (\n    IN num1 INT,\n    IN num2 INT,\n    OUT result INT\n)\nLANGUAGE SQL\nBEGIN\n    SET result = num1 + num2;\nEND<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528 CALL \u8bed\u53e5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CALL procedure_name (\n    -- \u53c2\u6570\u503c\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u540d\u79f0\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u53c2\u6570\u5fc5\u987b\u5177\u6709\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u4f53\u5fc5\u987b\u4ee5\u5206\u53f7 (;) \u7ed3\u5c3e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u5b9a\u4e49\u5b58\u50a8\u8fc7\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\u5b58\u50a8\u7684\u4e00\u7ec4 transact-sql \u8bed\u53e5\uff0c\u53ef\u6309\u9700\u8c03\u7528\uff0c\u7528\u4e8e\u5c01\u88c5\u76f8\u5173\u4ee3\u7801\u5757\u3002\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1. \u4f7f\u7528 create procedure \u8bed\u53e5\uff1b2. \u5b9a\u4e49\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\uff1b3. \u7f16\u5199\u5305\u542b transact-sql \u8bed\u53e5\u7684\u5b58\u50a8\u8fc7\u7a0b\u4f53\uff1b4. \u4f7f\u7528 end \u5173\u952e\u5b57\u7ed3\u675f\u5b58\u50a8\u8fc7\u7a0b\u3002 \u5982\u4f55\u5b9a\u4e49 MySQL \u5b58\u50a8\u8fc7\u7a0b \u5b9a\u4e49\uff1a\u5b58\u50a8\u8fc7\u7a0b\u662f MySQL \u4e2d\u5b58\u50a8\u7684\u4e00\u7ec4 Transact-SQL (T-SQL) \u8bed\u53e5\uff0c\u4ee5\u4fbf\u5728\u9700\u8981\u65f6\u88ab\u8c03\u7528\u3002\u5b83\u662f\u4e00\u79cd\u5c06\u76f8\u5173\u4ee3\u7801\u5757\u5c01\u88c5\u6210\u4e00\u4e2a\u72ec\u7acb\u5355\u5143\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u9700\u8981\u65f6\u9ad8\u6548\u5730\u6267\u884c\u3002 \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\uff1a 1. \u4f7f\u7528 CREATE PROCEDURE \u8bed\u53e5 CREATE PROCEDURE procedure_name ( &#8212; \u53c2\u6570\u5b9a\u4e49 ) LANGUAGE SQL &#8212; \u5b58\u50a8\u8fc7\u7a0b\u4f53 BEGIN &#8212; \u4ee3\u7801\u8bed\u53e5 END \u767b\u5f55\u540e\u590d\u5236 2. \u5b9a\u4e49\u53c2\u6570\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5177\u6709\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002\u5728 CREATE PROCEDURE \u8bed\u53e5\u4e2d\u4f7f\u7528 IN\u3001OUT \u6216 INOUT \u5173\u952e\u5b57\u6307\u5b9a\u53c2\u6570\u7c7b\u578b\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-5253","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5253","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=5253"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5253\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}