{"id":5654,"date":"2024-11-14T08:14:06","date_gmt":"2024-11-14T00:14:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5654\/"},"modified":"2024-11-14T08:14:06","modified_gmt":"2024-11-14T00:14:06","slug":"sql%e6%80%8e%e4%b9%88%e5%86%99%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5654\/","title":{"rendered":"sql\u600e\u4e48\u5199\u5b58\u50a8\u8fc7\u7a0b"},"content":{"rendered":"<p><strong>\u5982\u4f55\u4f7f\u7528 sql \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u662f\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u7ec4\u9884\u7f16\u8bd1 SQL \u8bed\u53e5\uff0c\u53ef\u4ee5\u5728\u4ee5\u540e\u901a\u8fc7\u5355\u4e2a\u8c03\u7528\u6765\u6267\u884c\u3002\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3001\u7b80\u5316\u4ee3\u7801\u5e76\u589e\u5f3a\u5b89\u5168\u6027\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>CREATE PROCEDURE \u8bed\u53e5\u7528\u4e8e\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/p>\n<pre>CREATE PROCEDURE [schema_name.]procedure_name\n(\n    [parameter_name] [data_type] [IN | OUT | INOUT],\n    ...\n)\nAS\nBEGIN\n    -- \u5b58\u50a8\u8fc7\u7a0b\u4e3b\u4f53\nEND<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6b65\u9aa4<\/strong><\/p>\n<ol>\n<li> <strong>\u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u540d\u79f0\u548c\u53c2\u6570\uff1a<\/strong>\u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\uff0c\u5e76\u5217\u51fa\u5176\u53c2\u6570\u3002\u53c2\u6570\u53ef\u4ee5\u6807\u8bb0\u4e3a IN\uff08\u8f93\u5165\uff09\u3001OUT\uff08\u8f93\u51fa\uff09\u6216 INOUT\uff08\u8f93\u5165\/\u8f93\u51fa\uff09\u3002<\/li>\n<li> <strong>\u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u4e3b\u4f53\uff1a<\/strong>\u4f7f\u7528 BEGIN \u548c END \u5757\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u7684\u4e3b\u4f53\uff0c\u5305\u62ec\u8981\u6267\u884c\u7684 SQL \u8bed\u53e5\u3002<\/li>\n<li> <strong>\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong>\u4f7f\u7528 CALL \u8bed\u53e5\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5e76\u4f20\u9012\u4efb\u4f55\u5fc5\u9700\u7684\u8f93\u5165\u53c2\u6570\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u5b58\u50a8\u8fc7\u7a0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a get_customer_by_id \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u83b7\u53d6\u5177\u6709\u7ed9\u5b9a ID \u7684\u5ba2\u6237\u7684\u4fe1\u606f\uff1a<\/p>\n<pre>CREATE PROCEDURE get_customer_by_id\n(\n    @id INT IN\n)\nAS\nBEGIN\n    SELECT * FROM Customers WHERE CustomerID = @id;\nEND<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f7f\u7528<\/strong><\/p>\n<p>\u8981\u6267\u884c\u6b64\u5b58\u50a8\u8fc7\u7a0b\u5e76\u83b7\u53d6\u5177\u6709 ID \u4e3a 1 \u7684\u5ba2\u6237\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b CALL \u8bed\u53e5\uff1a<\/p>\n<pre>CALL get_customer_by_id(1)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u5c06\u8fd4\u56de\u4e00\u4e2a\u7ed3\u679c\u96c6\uff0c\u5176\u4e2d\u5305\u542b\u5177\u6709 ID \u4e3a 1 \u7684\u5ba2\u6237\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u600e\u4e48\u5199\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>\u5982\u4f55\u4f7f\u7528 sql \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b \u5b58\u50a8\u8fc7\u7a0b\u662f\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u7ec4\u9884\u7f16\u8bd1 SQL \u8bed\u53e5\uff0c\u53ef\u4ee5\u5728\u4ee5\u540e\u901a\u8fc7\u5355\u4e2a\u8c03\u7528\u6765\u6267\u884c\u3002\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3001\u7b80\u5316\u4ee3\u7801\u5e76\u589e\u5f3a\u5b89\u5168\u6027\u3002 \u8bed\u6cd5 CREATE PROCEDURE \u8bed\u53e5\u7528\u4e8e\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff1a CREATE PROCEDURE [schema_name.]procedure_name ( [parameter_name] [data_type] [IN | OUT | INOUT], &#8230; ) AS BEGIN &#8212; \u5b58\u50a8\u8fc7\u7a0b\u4e3b\u4f53 END \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 \u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u540d\u79f0\u548c\u53c2\u6570\uff1a\u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\uff0c\u5e76\u5217\u51fa\u5176\u53c2\u6570\u3002\u53c2\u6570\u53ef\u4ee5\u6807\u8bb0\u4e3a IN\uff08\u8f93\u5165\uff09\u3001OUT\uff08\u8f93\u51fa\uff09\u6216 INOUT\uff08\u8f93\u5165\/\u8f93\u51fa\uff09\u3002 \u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u4e3b\u4f53\uff1a\u4f7f\u7528 BEGIN \u548c END \u5757\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u7684\u4e3b\u4f53\uff0c\u5305\u62ec\u8981\u6267\u884c\u7684 SQL \u8bed\u53e5\u3002 \u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\uff1a\u4f7f\u7528 CALL \u8bed\u53e5\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5e76\u4f20\u9012\u4efb\u4f55\u5fc5\u9700\u7684\u8f93\u5165\u53c2\u6570\u3002 \u793a\u4f8b \u4ee5\u4e0b\u5b58\u50a8\u8fc7\u7a0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a get_customer_by_id \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u83b7\u53d6\u5177\u6709\u7ed9\u5b9a ID \u7684\u5ba2\u6237\u7684\u4fe1\u606f\uff1a CREATE PROCEDURE get_customer_by_id ( @id INT [&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-5654","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5654","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=5654"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5654\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}