{"id":140,"date":"2005-11-04T15:43:28","date_gmt":"2005-11-04T07:43:28","guid":{"rendered":"http:\/\/www.2lin.net\/?p=51"},"modified":"2005-11-04T15:43:28","modified_gmt":"2005-11-04T07:43:28","slug":"51","status":"publish","type":"post","link":"https:\/\/www.2lin.top\/?p=140","title":{"rendered":"\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\uff0csp_executesql"},"content":{"rendered":"<p>\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\uff0csp_executesql <br \/>\u8bed\u8a00\u5728\u8fd9\u91cc\uff01 <\/p>\n<p>sp_executesql <br \/>\u6267\u884c\u53ef\u4ee5\u591a\u6b21\u91cd\u7528\u6216\u52a8\u6001\u751f\u6210\u7684 Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u3002Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u53ef\u4ee5\u5305\u542b\u5d4c\u5165\u53c2\u6570\u3002 <\/p>\n<p>\u8bed\u6cd5 <br \/>sp_executesql [@stmt =] stmt <br \/>[ <br \/>{, [@params =] <a href=\"mailto:N'@parameter_name\">N&#8217;@parameter_name<\/a> data_type [,&#8230;n]&#8217; } <br \/>{, [@param1 =] &#8216;value1&#8217; [,&#8230;n] } <br \/>] <\/p>\n<p>\u53c2\u6570 <br \/>[@stmt =] stmt <\/p>\n<p>\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\uff0csp_executesql <br \/>\u8bed\u8a00\u5728\u8fd9\u91cc\uff01 <\/p>\n<p>sp_executesql <br \/>\u6267\u884c\u53ef\u4ee5\u591a\u6b21\u91cd\u7528\u6216\u52a8\u6001\u751f\u6210\u7684 Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u3002Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u53ef\u4ee5\u5305\u542b\u5d4c\u5165\u53c2\u6570\u3002 <\/p>\n<p>\u8bed\u6cd5 <br \/>sp_executesql [@stmt =] stmt <br \/>[ <br \/>{, [@params =] <a href=\"mailto:N'@parameter_name\">N&#8217;@parameter_name<\/a> data_type [,&#8230;n]&#8217; } <br \/>{, [@param1 =] &#8216;value1&#8217; [,&#8230;n] } <br \/>] <\/p>\n<p>\u53c2\u6570 <br \/>[@stmt =] stmt <\/p>\n<p>\u5305\u542b Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u7684 Unicode \u5b57\u7b26\u4e32\uff0cstmt \u5fc5\u987b\u662f\u53ef\u4ee5\u9690\u5f0f\u8f6c\u6362\u4e3a ntext \u7684 Unicode \u5e38\u91cf\u6216\u53d8\u91cf\u3002\u4e0d\u5141\u8bb8\u4f7f\u7528\u66f4\u590d\u6742\u7684 Unicode \u8868\u8fbe\u5f0f\uff08\u4f8b\u5982\u4f7f\u7528 + \u8fd0\u7b97\u7b26\u4e32\u8054\u4e24\u4e2a\u5b57\u7b26\u4e32\uff09\u3002\u4e0d\u5141\u8bb8\u4f7f\u7528\u5b57\u7b26\u5e38\u91cf\u3002\u5982\u679c\u6307\u5b9a\u5e38\u91cf\uff0c\u5219\u5fc5\u987b\u4f7f\u7528 N \u4f5c\u4e3a\u524d\u7f00\u3002\u4f8b\u5982\uff0cUnicode \u5e38\u91cf N&#8217;sp_who&#8217; \u662f\u6709\u6548\u7684\uff0c\u4f46\u662f\u5b57\u7b26\u5e38\u91cf &#8216;sp_who&#8217; \u5219\u65e0\u6548\u3002\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u4ec5\u53d7\u53ef\u7528\u6570\u636e\u5e93\u670d\u52a1\u5668\u5185\u5b58\u9650\u5236\u3002 <\/p>\n<p>stmt \u53ef\u4ee5\u5305\u542b\u4e0e\u53d8\u91cf\u540d\u5f62\u5f0f\u76f8\u540c\u7684\u53c2\u6570\uff0c\u4f8b\u5982\uff1a <\/p>\n<p>N&#8217;SELECT * FROM Employees WHERE EmployeeID = @IDParameter&#8217; <\/p>\n<p>stmt \u4e2d\u5305\u542b\u7684\u6bcf\u4e2a\u53c2\u6570\u5728 @params \u53c2\u6570\u5b9a\u4e49\u5217\u8868\u548c\u53c2\u6570\u503c\u5217\u8868\u4e2d\u5747\u5fc5\u987b\u6709\u5bf9\u5e94\u9879\u3002 <\/p>\n<p>[@params =] <a href=\"mailto:N'@parameter_name\">N&#8217;@parameter_name<\/a> data_type [,&#8230;n]&#8217; <\/p>\n<p>\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u5df2\u5d4c\u5165\u5230 stmt \u4e2d\u7684\u6240\u6709\u53c2\u6570\u7684\u5b9a\u4e49\u3002\u8be5\u5b57\u7b26\u4e32\u5fc5\u987b\u662f\u53ef\u4ee5\u9690\u5f0f\u8f6c\u6362\u4e3a ntext \u7684 Unicode \u5e38\u91cf\u6216\u53d8\u91cf\u3002\u6bcf\u4e2a\u53c2\u6570\u5b9a\u4e49\u5747\u7531\u53c2\u6570\u540d\u548c\u6570\u636e\u7c7b\u578b\u7ec4\u6210\u3002n \u662f\u8868\u660e\u9644\u52a0\u53c2\u6570\u5b9a\u4e49\u7684\u5360\u4f4d\u7b26\u3002stmt \u4e2d\u6307\u5b9a\u7684\u6bcf\u4e2a\u53c2\u6570\u90fd\u5fc5\u987b\u5728 @params \u4e2d\u5b9a\u4e49\u3002\u5982\u679c stmt \u4e2d\u7684 Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u4e0d\u5305\u542b\u53c2\u6570\uff0c\u5219\u4e0d\u9700\u8981 @params\u3002\u8be5\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\u4e3a NULL\u3002 <\/p>\n<p>[@param1 =] &#8216;value1&#8217; <\/p>\n<p>\u53c2\u6570\u5b57\u7b26\u4e32\u4e2d\u5b9a\u4e49\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u503c\u3002\u8be5\u503c\u53ef\u4ee5\u662f\u5e38\u91cf\u6216\u53d8\u91cf\u3002\u5fc5\u987b\u4e3a stmt \u4e2d\u5305\u542b\u7684\u6bcf\u4e2a\u53c2\u6570\u63d0\u4f9b\u53c2\u6570\u503c\u3002\u5982\u679c stmt \u4e2d\u5305\u542b\u7684 Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u6ca1\u6709\u53c2\u6570\uff0c\u5219\u4e0d\u9700\u8981\u503c\u3002 <\/p>\n<p>n <\/p>\n<p>\u9644\u52a0\u53c2\u6570\u7684\u503c\u7684\u5360\u4f4d\u7b26\u3002\u8fd9\u4e9b\u503c\u53ea\u80fd\u662f\u5e38\u91cf\u6216\u53d8\u91cf\uff0c\u800c\u4e0d\u80fd\u662f\u66f4\u590d\u6742\u7684\u8868\u8fbe\u5f0f\uff0c\u4f8b\u5982\u51fd\u6570\u6216\u4f7f\u7528\u8fd0\u7b97\u7b26\u751f\u6210\u7684\u8868\u8fbe\u5f0f\u3002 <\/p>\n<p>\u8fd4\u56de\u4ee3\u7801\u503c <br \/>0\uff08\u6210\u529f\uff09\u6216 1\uff08\u5931\u8d25\uff09 <\/p>\n<p>\u6d4b\u8bd5\u529f\u80fd\u4e0e\u6548\u7387\u90fd\u6bd4\uff0cEXEC\u8981\u9ad8\uff01 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\uff0csp_executesql \u8bed\u8a00\u5728\u8fd9\u91cc\uff01 sp_executesql \u6267\u884c\u53ef\u4ee5\u591a\u6b21\u91cd\u7528\u6216\u52a8\u6001\u751f\u6210\u7684 Transact-SQL \u8bed\u53e5\u6216\u6279\u5904\u7406\u3002Transact-SQ&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/posts\/140"}],"collection":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=140"}],"version-history":[{"count":0,"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/posts\/140\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}