{"id":5547,"date":"2024-11-14T10:58:28","date_gmt":"2024-11-14T02:58:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5547\/"},"modified":"2024-11-14T10:58:28","modified_gmt":"2024-11-14T02:58:28","slug":"mysql%e6%80%8e%e4%b9%88%e8%b0%83%e7%94%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5547\/","title":{"rendered":"mysql\u600e\u4e48\u8c03\u7528\u51fd\u6570"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\uff0c\u901a\u8fc7 call \u8bed\u53e5\u8c03\u7528\u51fd\u6570\uff0c\u8be5\u8bed\u53e5\u5305\u542b\u51fd\u6570\u540d\u548c\u53c2\u6570\u5217\u8868\u3002\u8c03\u7528\u51fd\u6570\u7684\u6b65\u9aa4\u5305\u62ec\u521b\u5efa\u51fd\u6570\u548c\u4f7f\u7528 call \u8bed\u6cd5\u8c03\u7528\u5b83\u3002\u51fd\u6570\u53ef\u4ee5\u5177\u6709\u8f93\u5165\u53c2\u6570\uff08\u6570\u636e\u503c\uff09\u548c\u8f93\u51fa\u53c2\u6570\uff08\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u503c\uff09\uff0c\u8f93\u51fa\u53c2\u6570\u901a\u8fc7\u5f15\u7528\u7b26\u53f7\u4f20\u9012\u3002\u5728\u63d0\u4f9b\u793a\u4f8b\u4e4b\u524d\uff0c\u6458\u8981\u660e\u786e\u8bf4\u660e\u4e86\u51fd\u6570\u8c03\u7528\u7684\u8bed\u6cd5\u5f62\u5f0f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052909182379736.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u8c03\u7528\u51fd\u6570\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u8c03\u7528\u51fd\u6570\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u5728 MySQL \u4e2d\u8c03\u7528\u51fd\u6570<\/h2>\n<h3>\u8c03\u7528\u51fd\u6570\u7684\u5f62\u5f0f<\/h3>\n<p>\u5728 MySQL \u4e2d\uff0c\u8c03\u7528\u51fd\u6570\u7684\u8bed\u6cd5\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>CALL function_name(argument1, argument2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u8c03\u7528\u51fd\u6570\u7684\u6b65\u9aa4<\/h3>\n<p><strong>1. \u521b\u5efa\u51fd\u6570<\/strong><\/p>\n<p>\u5728\u8c03\u7528\u51fd\u6570\u4e4b\u524d\uff0c\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8be5\u51fd\u6570\u3002\u51fd\u6570\u7684\u521b\u5efa\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CREATE FUNCTION function_name(parameter_list)\nRETURNS return_type\nBEGIN\n  -- \u51fd\u6570\u4f53\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u8c03\u7528\u51fd\u6570<\/strong><\/p>\n<p>\u521b\u5efa\u51fd\u6570\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7 CALL \u8bed\u53e5\u8c03\u7528\u5b83\u3002\u5728 CALL \u8bed\u53e5\u4e2d\uff0c\u9700\u8981\u6307\u5b9a\u51fd\u6570\u540d\u548c\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570\uff08\u5982\u679c\u51fd\u6570\u6709\u53c2\u6570\uff09\u3002<\/p>\n<pre>CALL function_name(argument1, argument2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u51fd\u6570\u53c2\u6570<\/h3>\n<p>\u51fd\u6570\u53ef\u4ee5\u6709\u8f93\u5165\u53c2\u6570\u548c\u8f93\u51fa\u53c2\u6570\u3002\u8f93\u5165\u53c2\u6570\u662f\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u6570\u636e\u503c\uff0c\u800c\u8f93\u51fa\u53c2\u6570\u662f\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u503c\u3002<\/p>\n<p><strong>\u8f93\u5165\u53c2\u6570<\/strong><\/p>\n<p>\u8f93\u5165\u53c2\u6570\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u6307\u5b9a\uff0c\u5e76\u6309\u987a\u5e8f\u4f20\u9012\u7ed9\u51fd\u6570\u3002\u8f93\u5165\u53c2\u6570\u7684\u7c7b\u578b\u548c\u6570\u91cf\u5fc5\u987b\u4e0e\u51fd\u6570\u58f0\u660e\u4e2d\u6307\u5b9a\u7684\u4e00\u81f4\u3002<\/p>\n<p><strong>\u8f93\u51fa\u53c2\u6570<\/strong><\/p>\n<p>\u8f93\u51fa\u53c2\u6570\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u6307\u5b9a\u4e3a OUT \u6216 INOUT\uff0c\u5e76\u901a\u8fc7\u5f15\u7528\u7b26\u53f7 (@) \u4f20\u9012\u7ed9\u51fd\u6570\u3002\u8f93\u51fa\u53c2\u6570\u7684\u503c\u5728\u51fd\u6570\u6267\u884c\u540e\u88ab\u4fee\u6539\u3002<\/p>\n<h3>\u793a\u4f8b<\/h3>\n<p><strong>\u521b\u5efa\u51fd\u6570<\/strong><\/p>\n<pre>CREATE FUNCTION add_numbers(num1 INT, num2 INT)\nRETURNS INT\nBEGIN\n  RETURN num1 + num2;\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8c03\u7528\u51fd\u6570<\/strong><\/p>\n<pre>CALL add_numbers(10, 20);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p>30<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8c03\u7528\u51fd\u6570\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>\u5728 mysql \u4e2d\uff0c\u901a\u8fc7 call \u8bed\u53e5\u8c03\u7528\u51fd\u6570\uff0c\u8be5\u8bed\u53e5\u5305\u542b\u51fd\u6570\u540d\u548c\u53c2\u6570\u5217\u8868\u3002\u8c03\u7528\u51fd\u6570\u7684\u6b65\u9aa4\u5305\u62ec\u521b\u5efa\u51fd\u6570\u548c\u4f7f\u7528 call \u8bed\u6cd5\u8c03\u7528\u5b83\u3002\u51fd\u6570\u53ef\u4ee5\u5177\u6709\u8f93\u5165\u53c2\u6570\uff08\u6570\u636e\u503c\uff09\u548c\u8f93\u51fa\u53c2\u6570\uff08\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u503c\uff09\uff0c\u8f93\u51fa\u53c2\u6570\u901a\u8fc7\u5f15\u7528\u7b26\u53f7\u4f20\u9012\u3002\u5728\u63d0\u4f9b\u793a\u4f8b\u4e4b\u524d\uff0c\u6458\u8981\u660e\u786e\u8bf4\u660e\u4e86\u51fd\u6570\u8c03\u7528\u7684\u8bed\u6cd5\u5f62\u5f0f\u3002 \u5982\u4f55\u5728 MySQL \u4e2d\u8c03\u7528\u51fd\u6570 \u8c03\u7528\u51fd\u6570\u7684\u5f62\u5f0f \u5728 MySQL \u4e2d\uff0c\u8c03\u7528\u51fd\u6570\u7684\u8bed\u6cd5\u5f62\u5f0f\u5982\u4e0b\uff1a CALL function_name(argument1, argument2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u8c03\u7528\u51fd\u6570\u7684\u6b65\u9aa4 1. \u521b\u5efa\u51fd\u6570 \u5728\u8c03\u7528\u51fd\u6570\u4e4b\u524d\uff0c\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8be5\u51fd\u6570\u3002\u51fd\u6570\u7684\u521b\u5efa\u65b9\u6cd5\u5982\u4e0b\uff1a CREATE FUNCTION function_name(parameter_list) RETURNS return_type BEGIN &#8212; \u51fd\u6570\u4f53 END; \u767b\u5f55\u540e\u590d\u5236 2. \u8c03\u7528\u51fd\u6570 \u521b\u5efa\u51fd\u6570\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7 CALL \u8bed\u53e5\u8c03\u7528\u5b83\u3002\u5728 CALL \u8bed\u53e5\u4e2d\uff0c\u9700\u8981\u6307\u5b9a\u51fd\u6570\u540d\u548c\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570\uff08\u5982\u679c\u51fd\u6570\u6709\u53c2\u6570\uff09\u3002 CALL function_name(argument1, argument2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u51fd\u6570\u53c2\u6570 \u51fd\u6570\u53ef\u4ee5\u6709\u8f93\u5165\u53c2\u6570\u548c\u8f93\u51fa\u53c2\u6570\u3002\u8f93\u5165\u53c2\u6570\u662f\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u6570\u636e\u503c\uff0c\u800c\u8f93\u51fa\u53c2\u6570\u662f\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u503c\u3002 \u8f93\u5165\u53c2\u6570 \u8f93\u5165\u53c2\u6570\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u6307\u5b9a\uff0c\u5e76\u6309\u987a\u5e8f\u4f20\u9012\u7ed9\u51fd\u6570\u3002\u8f93\u5165\u53c2\u6570\u7684\u7c7b\u578b\u548c\u6570\u91cf\u5fc5\u987b\u4e0e\u51fd\u6570\u58f0\u660e\u4e2d\u6307\u5b9a\u7684\u4e00\u81f4\u3002 \u8f93\u51fa\u53c2\u6570 \u8f93\u51fa\u53c2\u6570\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u6307\u5b9a\u4e3a OUT \u6216 [&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-5547","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5547","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=5547"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5547\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}