{"id":233413,"date":"2022-01-14T08:13:58","date_gmt":"2022-01-14T00:13:58","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=233413"},"modified":"2021-12-30T13:19:56","modified_gmt":"2021-12-30T05:19:56","slug":"sqlserver-declare-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sqlserver-declare-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdSQLserver\u4e2d\u7684declare\u53d8\u91cf\u7528\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86SQLserver\u4e2d\u7684declare\u53d8\u91cf\u7528\u6cd5\uff0csql\u4e2ddeclare\u662f\u58f0\u660e\u7684\u610f\u601d\uff0c\u5c31\u662f\u58f0\u660e\u53d8\u91cf\u7684\uff0c\u8fd9\u4e2a\u4e00\u822c\u662f\u7528\u5728\u51fd\u6570\u548c\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u7684\u3002\u611f\u5174\u8da3\u7684\u53ef\u4ee5\u6765\u4e86\u89e3\u4e00\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5e73\u65f6\u5199SQL\u67e5\u8be2\u3001\u5b58\u50a8\u8fc7\u7a0b\u90fd\u662f\u51ed\u7740\u611f\u89c9\u6765\uff0c\u6ca1\u6709\u63a2\u7a76\u8fc7SQL\u7684\u5177\u4f53\u8bed\u6cd5\uff0c\u4e00\u76f4\u90fd\u662f\u6309c#\u90a3\u4e00\u5957\u5f80SQL\u4e0a\u6a21\u4eff\uff0c\u524d\u51e0\u5929\u9879\u76ee\u4e2d\u78b0\u5230\u4e00\u4e2a\u95ee\u9898\u5f15\u8d77\u4e86\u6211\u5bf9declare\u5b9a\u4e49\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u7684\u5174\u8da3\u3002<\/p>\n

\u5927\u5bb6\u90fd\u77e5\u9053c#\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u5728if\u4e2d\u5982\u679c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u7684\u8bdd\u4ed6\u7684\u4f5c\u7528\u5230if\u7ed3\u675f\u4e3a\u6b62\uff0cif\u5916\u662f\u4e0d\u8bc6\u522b\u8fd9\u4e2a\u53d8\u91cf\u7684\uff0celse\u91cc\u90fd\u4e0d\u80fd\u4f7f\u7528\uff0c\u7b80\u5355\u7684\u5199\u4e00\u4e0b\u3002<\/p>\n

\r\nif(true)\r\n{\r\nInt32i=1;\r\nConsole.WriteLine(i);\r\n}<\/pre>\n

\u8fd9\u4e2ai\u7684\u4f5c\u7528\u57df\u5c31\u662fif\u91cc\u9762\uff0c\u5982\u679c\u6211\u4eec\u5728if\u5916\u9762\u7528\u8fd9\u4e2a\u53d8\u91cf<\/p>\n

\r\nif(true)\r\n{\r\nInt32i=1;\r\nConsole.WriteLine(i);\r\n}\r\nConsole.WriteLine(i);<\/pre>\n

\u90a3\u7b2c\u4e8c\u6761\u8f93\u51fa\u8bed\u53e5\u4f1a\u62a5\u9519<\/p>\n

The name 'i' does not exist in the current context<\/pre>\n

\u8bf4\u660e\u5df2\u7ecf\u51fa\u4e86i\u7684\u4f5c\u7528\u57df\u4e86\u3002<\/p>\n

\u90a3\u4e48\u6211\u4eec\u8981\u662f\u5728sql\u5199\u8fd9\u4e48\u4e00\u6bb5\u4ee3\u7801\u4f1a\u662f\u4ec0\u4e48\u60c5\u51b5\u5462\uff1f\u9996\u5148\u5199\u5728if\u5185<\/p>\n

\r\nIF1=1\r\nBEGIN\r\nDECLARE@testVARCHAR\r\nSET@test='1'\r\nPRINT'inif:'+@test\r\nEND<\/pre>\n

\u8fd0\u884c\u770b\u7ed3\u679c\u8f93\u51fain if:1\u8fd9\u662f\u53ef\u4ee5\u9884\u60f3\u7684\u7ed3\u679c\u3002\u90a3\u6211\u4eec\u5728if\u5916\u9762\u4f7f\u7528\u53d8\u91cf@test\u8bd5\u8bd5\u3002<\/p>\n

\r\nIF1=1\r\nBEGIN\r\nDECLARE@testVARCHAR\r\nSET@test='1'\r\nPRINT'inif:'+@test\r\nEND\r\nPRINT'outif:'+@test<\/pre>\n

\u8fd9\u6837\u4f1a\u662f\u4ec0\u4e48\u7ed3\u679c\u5462\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u600e\u4e48\u60f3\u7684\uff0c\u4ee5\u6211\u7684\u5927\u8111\u987a\u52bf\u5c31\u60f3\u5230\u8fd9\u5e94\u8be5\u62a5\u9519\u554a\uff0c\u51fa\u4e86\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u4e86\u3002\u5b9e\u9645\u7ed3\u679c\u4e0d\u4ec5\u6ca1\u62a5\u9519\u800c\u4e14@test\u7684\u503c\u8fd8\u5728\u3002<\/p>\n

in if:1\r\n\r\nout if:1<\/pre>\n

\u770b\u89c1\u8fd9\u4e2a\u7ed3\u679c\u5f53\u65f6\u6211\u5f88\u90c1\u95f7\uff0cSQL\u592a\u51fa\u4eba\u610f\u6599\u4e86\u3002<\/p>\n

\u5728SQL SERVER 2005\u7684\u5e2e\u52a9\u6587\u6863\u91cc\u5173\u4e8edeclare\u7684\u5e2e\u52a9\u91cc\u53d1\u73b0\u8fd9\u4e48\u4e00\u53e5\u8bdd\uff0c\u5907\u6ce8\u7684\u7b2c\u4e09\u884c\u201c\u5c40\u90e8\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u662f\u5176\u88ab\u58f0\u660e\u65f6\u6240\u5728\u6279\u5904\u7406\u201d<\/p>\n

\u8fd9\u884c\u5b57\u5728\u8fd9\u4e48\u4e00\u5927\u7bc7\u4e2d\u8fd8\u771f\u633a\u4e0d\u5f15\u4eba\u77a9\u76ee\u3002<\/p>\n

\u73b0\u5728\u6211\u4eec\u77e5\u9053\u539f\u6765declare\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u662f\u6240\u5728\u7684\u6279\u5904\u7406\uff0cif\u963b\u65ad\u4e0d\u4e86\u5b83\u7684\u4f5c\u7528\u57df\uff0c\u90a3\u4e0a\u9762\u6211\u4eec\u7684\u4ee3\u7801if\u5185\u5916\u7684\u4ee3\u7801\u90fd\u5728\u4e00\u4e2a\u6279\u5904\u7406\u4e2d\uff0c\u6240\u4ee5@test\u90fd\u662f\u53ef\u7528\u7684\u4e14if\u91cc\u9762\u8bbe\u7f6e\u7684\u503c\u8fd8\u5728\u3002<\/p>\n

\u4e0b\u9762\u6211\u6539\u9020\u4e00\u4e0b\u4ee3\u7801\uff0cSQL\u4e2d\u662f\u4ee5GO\u8bed\u53e5\u6765\u533a\u5206\u6279\u5904\u7406\u7684<\/p>\n

\r\nIF1=1\r\nBEGIN\r\nDECLARE@testVARCHAR\r\nSET@test='1'\r\nPRINT'inif:'+@test\r\nEND\r\nGO\r\nPRINT'outif:'+@test<\/pre>\n

\u8fd9\u4e0b\u5bf9\u4e86\uff0c\u68c0\u67e5\u8bed\u6cd5\u540eSQL\u62a5\u9519\u201c\u5fc5\u987b\u58f0\u660e\u6807\u91cf\u53d8\u91cf\"@test\"\u201d<\/p>\n

\u6ce8\uff1aGO\u5c31\u662f\u7528\u4e8e\u4e00\u4e2asql\u8bed\u53e5\u7684\u7ed3\u675f \u6bd4\u5982\u8bf4\u4e00\u4e2a\u6279\u5904\u7406\u8bed\u53e5\u662f\u8fd9\u6837\u7684 select *from ,b select *from a \u5728\u540e\u4e00\u4e2aselect\u540e\u9762\u52a0\u4e0a\u4e00\u4e2aGO\u8fd9\u6837\u53ef\u4ee5\u4e00\u6b21\u6267\u884c\u4e24\u6761sql \u8bed\u53e5<\/p>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eSQL server\u4e2d\u7684declare\u53d8\u91cf\u7528\u6cd5\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5e73\u65f6\u5199SQL\u67e5\u8be2\u3001\u5b58\u50a8\u8fc7\u7a0b\u90fd\u662f\u51ed\u7740\u611f\u89c9\u6765\uff0c\u6ca1\u6709\u63a2\u7a76\u8fc7SQL\u7684\u5177\u4f53\u8bed\u6cd5\uff0c\u4e00\u76f4\u90fd\u662f\u6309c#\u90a3\u4e00\u5957\u5f80SQL\u4e0a\u6a21\u4eff\uff0c\u524d\u51e0 […]<\/p>\n","protected":false},"author":1482,"featured_media":79561,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-233413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=233413"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233413\/revisions"}],"predecessor-version":[{"id":233417,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233413\/revisions\/233417"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/79561"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=233413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=233413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=233413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}