{"id":200038,"date":"2025-05-06T11:30:17","date_gmt":"2025-05-06T03:30:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200038\/"},"modified":"2025-05-06T11:30:17","modified_gmt":"2025-05-06T03:30:17","slug":"%e6%b7%b1%e5%85%a5%e6%8e%a2%e8%ae%a8mysql%e4%b8%ad%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e4%b8%8epl-sql%e7%9a%84%e8%81%94%e7%b3%bb","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200038\/","title":{"rendered":"\u6df1\u5165\u63a2\u8ba8MySQL\u4e2d\u5b58\u50a8\u8fc7\u7a0b\u4e0ePL\/SQL\u7684\u8054\u7cfb"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u6df1\u5165\u63a2\u8ba8MySQL\u4e2d\u5b58\u50a8\u8fc7\u7a0b\u4e0ePL\/SQL\u7684\u8054\u7cfb<\/h1>\n<\/p>\n<p>\u6807\u9898\uff1a\u63a2\u7a76MySQL\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\u4e0ePL\/SQL\u7684\u5173\u7cfb<\/p>\n<p>\u5728\u6570\u636e\u5e93\u5f00\u53d1\u4e2d\uff0c\u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u79cd\u9884\u5148\u7f16\u8bd1\u7684SQL\u8bed\u53e5\u96c6\u5408\uff0c\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a\u6267\u884c\u3002MySQL\u662f\u4e00\u79cd\u6d41\u884c\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u5b83\u652f\u6301\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f7f\u7528\u3002\u800cPL\/SQL\u662fOracle\u6570\u636e\u5e93\u7279\u6709\u7684\u8fc7\u7a0b\u5316\u7f16\u7a0b\u8bed\u8a00\uff0c\u7c7b\u4f3c\u4e8e\u5b58\u50a8\u8fc7\u7a0b\uff0c\u4f46\u5177\u6709\u66f4\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u8bed\u6cd5\u3002<\/p>\n<p>MySQL\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u8bf4\u662fSQL\u8bed\u53e5\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u88ab\u8c03\u7528\u548c\u6267\u884c\u3002\u5b83\u53ef\u4ee5\u5305\u542b\u903b\u8f91\u63a7\u5236\u3001\u6d41\u7a0b\u63a7\u5236\u3001\u5faa\u73af\u3001\u6761\u4ef6\u63a7\u5236\u7b49\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002\u800cPL\/SQL\u662f\u4e00\u79cd\u8fc7\u7a0b\u5316\u7f16\u7a0b\u8bed\u8a00\uff0c\u7ed3\u5408\u4e86SQL\u7684\u8bed\u6cd5\u548c\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\uff0c\u53ef\u4ee5\u5728Oracle\u6570\u636e\u5e93\u4e2d\u7f16\u5199\u5b58\u50a8\u8fc7\u7a0b\u3001\u51fd\u6570\u3001\u89e6\u53d1\u5668\u7b49\u3002<\/p>\n<p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3MySQL\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\u4e0ePL\/SQL\u7684\u5173\u7cfb\uff0c\u8ba9\u6211\u4eec\u901a\u8fc7\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684MySQL\u5b58\u50a8\u8fc7\u7a0b\u793a\u4f8b\uff1a<\/p>\n<pre>DELIMITER \/\/\nCREATE PROCEDURE get_employee(IN employee_id INT)\nBEGIN\n    SELECT * FROM employees WHERE employee_id = employee_id;\nEND \/\/\nDELIMITER ;<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>get_employee<\/code>\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570<code>employee_id<\/code>\uff0c\u7136\u540e\u4ece<code>employees<\/code>\u8868\u4e2d\u67e5\u8be2\u51fa\u5bf9\u5e94\u7684\u5458\u5de5\u4fe1\u606f\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u7b80\u5355\u7684PL\/SQL\u5b58\u50a8\u8fc7\u7a0b\u793a\u4f8b\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u5728Oracle\u6570\u636e\u5e93\u4e2d\u5b9e\u73b0\u548c\u4e0a\u9762\u76f8\u540c\u529f\u80fd\u7684\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/p>\n<pre>CREATE OR REPLACE PROCEDURE get_employee(employee_id IN NUMBER)\nIS\n    v_employee employees%rowtype;\nBEGIN\n    SELECT * INTO v_employee FROM employees WHERE employee_id = get_employee.employee_id;\nEND;<\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528PL\/SQL\u8bed\u6cd5\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>get_employee<\/code>\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5e76\u901a\u8fc7<code>INTO<\/code>\u5b50\u53e5\u5c06\u67e5\u8be2\u7ed3\u679c\u8d4b\u503c\u7ed9<code>v_employee<\/code>\u53d8\u91cf\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cPL\/SQL\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\u9700\u8981\u4f7f\u7528<code>CREATE OR REPLACE PROCEDURE<\/code>\u8bed\u53e5\u6765\u521b\u5efa\u6216\u66ff\u6362\u5df2\u6709\u7684\u5b58\u50a8\u8fc7\u7a0b\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cMySQL\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\u548cPL\/SQL\u7684\u8bed\u6cd5\u6709\u4e00\u4e9b\u533a\u522b\uff0c\u4f46\u5b83\u4eec\u90fd\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u4f3c\u7684\u529f\u80fd\u3002MySQL\u5b58\u50a8\u8fc7\u7a0b\u66f4\u504f\u5411\u4e8eSQL\u8bed\u53e5\u7684\u96c6\u5408\uff0c\u800cPL\/SQL\u5219\u662f\u4e00\u79cd\u5b8c\u6574\u7684\u8fc7\u7a0b\u5316\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728\u529f\u80fd\u548c\u8bed\u6cd5\u4e0a\u66f4\u52a0\u4e30\u5bcc\u548c\u5f3a\u5927\u3002<\/p>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u5b58\u50a8\u8fc7\u7a0b\u662f\u6570\u636e\u5e93\u5f00\u53d1\u4e2d\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u5b83\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\uff0c\u51cf\u5c11\u91cd\u590d\u7684\u4ee3\u7801\u7f16\u5199\u3002\u4e86\u89e3MySQL\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\u4e0ePL\/SQL\u7684\u5173\u7cfb\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u66f4\u597d\u5730\u5229\u7528\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u529f\u80fd\uff0c\u63d0\u5347\u5de5\u4f5c\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002\u5e0c\u671b\u672c\u6587\u7684\u4ee3\u7801\u793a\u4f8b\u80fd\u5bf9\u8bfb\u8005\u6709\u6240\u5e2e\u52a9\uff0c\u8ba9\u5927\u5bb6\u66f4\u597d\u5730\u7406\u89e3\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f7f\u7528\u548c\u76f8\u5173\u6982\u5ff5\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u6df1\u5165\u63a2\u8ba8MySQL\u4e2d\u5b58\u50a8\u8fc7\u7a0b\u4e0ePL\/SQL\u7684\u8054\u7cfb\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u63a2\u8ba8MySQL\u4e2d\u5b58\u50a8\u8fc7\u7a0b\u4e0eP&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200038","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200038","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200038"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200038\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}