{"id":5926,"date":"2024-11-14T09:40:48","date_gmt":"2024-11-14T01:40:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5926\/"},"modified":"2024-11-14T09:40:48","modified_gmt":"2024-11-14T01:40:48","slug":"sql%e6%80%8e%e4%b9%88%e8%b0%83%e7%94%a8%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5926\/","title":{"rendered":"sql\u600e\u4e48\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\uff1acall procedure_name(parameter1, parameter2, &#8230;)\u3002\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u7c7b\u578b\u53ef\u4ee5\u662f\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u7c7b\u578b\uff0c\u8bed\u6cd5\u4e3a\uff1acall procedure_name(in | out | inout parameter_name datatype)\u3002\u8981\u83b7\u53d6\u8f93\u51fa\u53c2\u6570\u7684\u503c\uff0c\u4f7f\u7528 @ \u7b26\u53f7\uff0c\u540e\u8ddf\u53c2\u6570\u540d\u79f0\uff1aselect @output_parameter_name;\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060322340365127.jpg\" class=\"aligncenter\" title=\"sql\u600e\u4e48\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u63d2\u56fe\" alt=\"sql\u600e\u4e48\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 SQL \u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u548c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u5df2\u547d\u540d SQL \u4ee3\u7801\u5757\u3002\u5b83\u4eec\u88ab\u7528\u6765\u6267\u884c\u5e38\u89c1\u7684\u6216\u590d\u6742\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u548c\u4ee3\u7801\u53ef\u91cd\u7528\u6027\u3002<\/p>\n<p><strong>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CALL procedure_name(parameter1, parameter2, ...);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>procedure_name \u662f\u8981\u8c03\u7528\u7684\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\u3002<\/li>\n<li>parameter1, parameter2, &#8230; \u662f\u8981\u4f20\u9012\u7ed9\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u8c03\u7528\u540d\u4e3a GetCustomerOrders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u9700\u8981\u4e00\u4e2a\u53c2\u6570 customer_id\uff1a<\/p>\n<pre>CALL GetCustomerOrders(10);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f20\u9012\u53c2\u6570\u7c7b\u578b<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u4ee5\u4e0b\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li> <strong>\u8f93\u5165\u53c2\u6570\uff1a<\/strong>\u7528\u4e8e\u4f20\u9012\u503c\u7ed9\u5b58\u50a8\u8fc7\u7a0b\u3002<\/li>\n<li> <strong>\u8f93\u51fa\u53c2\u6570\uff1a<\/strong>\u7528\u4e8e\u4ece\u5b58\u50a8\u8fc7\u7a0b\u8fd4\u56de\u503c\u3002<\/li>\n<li> <strong>\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\uff1a<\/strong>\u65e2\u53ef\u4ee5\u4f20\u9012\u503c\u7ed9\u5b58\u50a8\u8fc7\u7a0b\uff0c\u53c8\u53ef\u4ee5\u4ece\u5b58\u50a8\u8fc7\u7a0b\u8fd4\u56de\u503c\u3002<\/li>\n<\/ul>\n<p>\u4f20\u9012\u53c2\u6570\u7c7b\u578b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CALL procedure_name(IN | OUT | INOUT parameter_name datatype);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>IN, OUT, INOUT \u6307\u5b9a\u53c2\u6570\u7c7b\u578b\u3002<\/li>\n<li>parameter_name \u662f\u53c2\u6570\u7684\u540d\u79f0\u3002<\/li>\n<li>datatype \u662f\u53c2\u6570\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p><strong>\u83b7\u53d6\u8f93\u51fa\u53c2\u6570\u503c<\/strong><\/p>\n<p>\u8981\u83b7\u53d6\u8f93\u51fa\u53c2\u6570\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 @ \u7b26\u53f7\uff0c\u540e\u8ddf\u53c2\u6570\u540d\u79f0\uff1a<\/p>\n<pre>SELECT @output_parameter_name;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u540d\u79f0\u5fc5\u987b\u5b58\u5728\u4e8e\u5f53\u524d\u6570\u636e\u5e93\u6216 schema \u4e2d\u3002<\/li>\n<li>\u53c2\u6570\u5217\u8868\u5fc5\u987b\u4e0e\u5b58\u50a8\u8fc7\u7a0b\u5b9a\u4e49\u4e2d\u7684\u53c2\u6570\u5217\u8868\u5339\u914d\u3002<\/li>\n<li>\u8f93\u51fa\u53c2\u6570\u5fc5\u987b\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u58f0\u660e\u4e3a OUT \u6216 INOUT\u3002<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u7ed3\u679c\u96c6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u600e\u4e48\u8c03\u7528\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>\u5728 sql \u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\uff1acall procedure_name(parameter1, parameter2, &#8230;)\u3002\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u7c7b\u578b\u53ef\u4ee5\u662f\u8f93\u5165\u3001\u8f93\u51fa\u6216\u8f93\u5165\/\u8f93\u51fa\u7c7b\u578b\uff0c\u8bed\u6cd5\u4e3a\uff1acall procedure_name(in | out | inout parameter_name datatype)\u3002\u8981\u83b7\u53d6\u8f93\u51fa\u53c2\u6570\u7684\u503c\uff0c\u4f7f\u7528 @ \u7b26\u53f7\uff0c\u540e\u8ddf\u53c2\u6570\u540d\u79f0\uff1aselect @output_parameter_name;\u3002 \u5982\u4f55\u5728 SQL \u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b \u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u548c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u5df2\u547d\u540d SQL \u4ee3\u7801\u5757\u3002\u5b83\u4eec\u88ab\u7528\u6765\u6267\u884c\u5e38\u89c1\u7684\u6216\u590d\u6742\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u548c\u4ee3\u7801\u53ef\u91cd\u7528\u6027\u3002 \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5 \u5728 SQL \u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a CALL procedure_name(parameter1, parameter2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a procedure_name \u662f\u8981\u8c03\u7528\u7684\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\u3002 parameter1, parameter2, &#8230; \u662f\u8981\u4f20\u9012\u7ed9\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u3002 \u793a\u4f8b \u4ee5\u4e0b\u793a\u4f8b\u8c03\u7528\u540d\u4e3a GetCustomerOrders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u9700\u8981\u4e00\u4e2a\u53c2\u6570 customer_id\uff1a CALL GetCustomerOrders(10); \u767b\u5f55\u540e\u590d\u5236 \u4f20\u9012\u53c2\u6570\u7c7b\u578b \u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u4ee5\u4e0b\u7c7b\u578b\uff1a \u8f93\u5165\u53c2\u6570\uff1a\u7528\u4e8e\u4f20\u9012\u503c\u7ed9\u5b58\u50a8\u8fc7\u7a0b\u3002 \u8f93\u51fa\u53c2\u6570\uff1a\u7528\u4e8e\u4ece\u5b58\u50a8\u8fc7\u7a0b\u8fd4\u56de\u503c\u3002 \u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\uff1a\u65e2\u53ef\u4ee5\u4f20\u9012\u503c\u7ed9\u5b58\u50a8\u8fc7\u7a0b\uff0c\u53c8\u53ef\u4ee5\u4ece\u5b58\u50a8\u8fc7\u7a0b\u8fd4\u56de\u503c\u3002 \u4f20\u9012\u53c2\u6570\u7c7b\u578b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a CALL procedure_name(IN | [&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-5926","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5926","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=5926"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5926\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}