{"id":5918,"date":"2024-11-14T12:00:28","date_gmt":"2024-11-14T04:00:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5918\/"},"modified":"2024-11-14T12:00:28","modified_gmt":"2024-11-14T04:00:28","slug":"sql%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e6%80%8e%e4%b9%88%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5918\/","title":{"rendered":"sql\u5b58\u50a8\u8fc7\u7a0b\u600e\u4e48\u8fd0\u884c"},"content":{"rendered":"<blockquote><p>\n  sql \u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u5148\u7f16\u8bd1\u7684 sql \u8bed\u53e5\u96c6\u5408\uff0c\u7528\u4e8e\u6267\u884c\u590d\u6742\u64cd\u4f5c\uff0c\u63d0\u9ad8\u6027\u80fd\u3002\u8fd0\u884c\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1) \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff08\u4f7f\u7528 create procedure\uff09\uff1b2) \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff08\u4f7f\u7528 exec \u8bed\u6cd5\uff0c\u6307\u5b9a\u6a21\u5f0f\u3001\u540d\u79f0\u548c\u53c2\u6570\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060322215253285.jpg\" class=\"aligncenter\" title=\"sql\u5b58\u50a8\u8fc7\u7a0b\u600e\u4e48\u8fd0\u884c\u63d2\u56fe\" alt=\"sql\u5b58\u50a8\u8fc7\u7a0b\u600e\u4e48\u8fd0\u884c\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u5b58\u50a8\u8fc7\u7a0b\u7684\u8fd0\u884c<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u5148\u7f16\u8bd1\u7684 SQL \u8bed\u53e5\u96c6\u5408\uff0c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u5e76\u53ef\u591a\u6b21\u8c03\u7528\u3002\u5b83\u4eec\u7528\u4e8e\u6267\u884c\u590d\u6742\u6216\u91cd\u590d\u6027\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u548c\u6548\u7387\u3002<\/p>\n<p><strong>\u8fd0\u884c\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong>\u4f7f\u7528 SQL \u8bed\u53e5 CREATE PROCEDURE \u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u3002<\/li>\n<li> <strong>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong>\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/li>\n<\/ol>\n<pre>EXEC [schema_name].[procedure_name] [parameters];<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>schema_name\uff08\u53ef\u9009\uff09\uff1a\u5b58\u50a8\u8fc7\u7a0b\u6240\u5728\u6a21\u5f0f\u7684\u540d\u79f0\u3002<\/li>\n<li>procedure_name\uff1a\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\u3002<\/li>\n<li>parameters\uff08\u53ef\u9009\uff09\uff1a\u4f20\u9012\u7ed9\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u5217\u8868\u3002<\/li>\n<\/ul>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63a5\u53d7\u8f93\u5165\u53c2\u6570\u3001\u8f93\u51fa\u53c2\u6570\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002\u5728\u8c03\u7528\u4e2d\u5fc5\u987b\u6307\u5b9a\u53c2\u6570\u503c\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a GetCustomerOrders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u5ba2\u6237 ID \u53c2\u6570\u5e76\u8fd4\u56de\u8be5\u5ba2\u6237\u7684\u6240\u6709\u8ba2\u5355\uff1a<\/p>\n<pre>CREATE PROCEDURE GetCustomerOrders\n(\n  @CustomerID INT\n)\nAS\nBEGIN\n  SELECT * FROM Orders WHERE CustomerID = @CustomerID;\nEND;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8981\u8c03\u7528\u6b64\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>EXEC GetCustomerOrders @CustomerID = 12345;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u5c06\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u5e76\u68c0\u7d22\u5ba2\u6237 12345 \u7684\u6240\u6709\u8ba2\u5355\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u5b58\u50a8\u8fc7\u7a0b\u600e\u4e48\u8fd0\u884c\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>sql \u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u5148\u7f16\u8bd1\u7684 sql \u8bed\u53e5\u96c6\u5408\uff0c\u7528\u4e8e\u6267\u884c\u590d\u6742\u64cd\u4f5c\uff0c\u63d0\u9ad8\u6027\u80fd\u3002\u8fd0\u884c\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1) \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff08\u4f7f\u7528 create procedure\uff09\uff1b2) \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff08\u4f7f\u7528 exec \u8bed\u6cd5\uff0c\u6307\u5b9a\u6a21\u5f0f\u3001\u540d\u79f0\u548c\u53c2\u6570\uff09\u3002 SQL \u5b58\u50a8\u8fc7\u7a0b\u7684\u8fd0\u884c \u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u5148\u7f16\u8bd1\u7684 SQL \u8bed\u53e5\u96c6\u5408\uff0c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u5e76\u53ef\u591a\u6b21\u8c03\u7528\u3002\u5b83\u4eec\u7528\u4e8e\u6267\u884c\u590d\u6742\u6216\u91cd\u590d\u6027\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u548c\u6548\u7387\u3002 \u8fd0\u884c\u5b58\u50a8\u8fc7\u7a0b\u7684\u6b65\u9aa4\uff1a \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff1a\u4f7f\u7528 SQL \u8bed\u53e5 CREATE PROCEDURE \u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u3002 \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1a EXEC [schema_name].[procedure_name] [parameters]; \u767b\u5f55\u540e\u590d\u5236 schema_name\uff08\u53ef\u9009\uff09\uff1a\u5b58\u50a8\u8fc7\u7a0b\u6240\u5728\u6a21\u5f0f\u7684\u540d\u79f0\u3002 procedure_name\uff1a\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\u3002 parameters\uff08\u53ef\u9009\uff09\uff1a\u4f20\u9012\u7ed9\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u5217\u8868\u3002 \u53c2\u6570\uff1a \u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63a5\u53d7\u8f93\u5165\u53c2\u6570\u3001\u8f93\u51fa\u53c2\u6570\u6216\u8f93\u5165\/\u8f93\u51fa\u53c2\u6570\u3002\u5728\u8c03\u7528\u4e2d\u5fc5\u987b\u6307\u5b9a\u53c2\u6570\u503c\u3002 \u793a\u4f8b\uff1a \u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a GetCustomerOrders \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u5ba2\u6237 ID \u53c2\u6570\u5e76\u8fd4\u56de\u8be5\u5ba2\u6237\u7684\u6240\u6709\u8ba2\u5355\uff1a CREATE PROCEDURE GetCustomerOrders ( @CustomerID INT ) AS BEGIN SELECT * FROM Orders WHERE CustomerID = @CustomerID; [&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-5918","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5918","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=5918"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5918\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}