{"id":185950,"date":"2024-11-11T01:51:20","date_gmt":"2024-11-10T17:51:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/185950\/"},"modified":"2024-11-11T01:51:21","modified_gmt":"2024-11-10T17:51:21","slug":"%e6%95%b8%e6%93%9a%e5%ba%abcursor%ef%bc%9a%e4%ba%86%e8%a7%a3%e5%ae%83%e6%98%af%e5%a6%82%e4%bd%95%e5%84%aa%e5%8c%96%e6%95%b8%e6%93%9a%e8%a8%aa%e5%95%8f%e9%80%9f%e5%ba%a6%e7%9a%84%ef%bc%88%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/185950\/","title":{"rendered":"\u6578\u64da\u5eabcursor\uff1a\u4e86\u89e3\u5b83\u662f\u5982\u4f55\u512a\u5316\u6578\u64da\u8a2a\u554f\u901f\u5ea6\u7684\uff08\u6578\u64da\u5eabcursor\uff09"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%abcursor%ef%bc%9a%e4%ba%86%e8%a7%a3%e5%ae%83%e6%98%af%e5%a6%82%e4%bd%95%e5%84%aa%e5%8c%96%e6%95%b8%e6%93%9a%e8%a8%aa%e5%95%8f%e9%80%9f%e5%ba%a6%e7%9a%84-qPyAGWwpQq\">\u6578\u64da\u5eabcursor\uff1a\u4e86\u89e3\u5b83\u662f\u5982\u4f55\u512a\u5316\u6578\u64da\u8a2a\u554f\u901f\u5ea6\u7684<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0ccursor\uff08\u6e38\u6a19\uff09\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5c24\u5176\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u3002\u6e38\u6a19\u5141\u8a31\u958b\u767c\u8005\u9010\u884c\u8a2a\u554f\u67e5\u8a62\u7d50\u679c\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u9010\u6b65\u8655\u7406\u6578\u64da\u7684\u61c9\u7528\u7a0b\u5e8f\u4f86\u8aaa\u662f\u975e\u5e38\u6709\u7528\u7684\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u6e38\u6a19\u7684\u5de5\u4f5c\u539f\u7406\u53ca\u5176\u5982\u4f55\u512a\u5316\u6578\u64da\u8a2a\u554f\u901f\u5ea6\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%b8%b8%e6%a8%99%ef%bc%9f-qPyAGWwpQq\">\u4ec0\u9ebc\u662f\u6e38\u6a19\uff1f<\/h2>\n<p>\u6e38\u6a19\u662f\u4e00\u7a2e\u6578\u64da\u5eab\u5c0d\u8c61\uff0c\u7528\u65bc\u5728\u67e5\u8a62\u7d50\u679c\u96c6\u4e2d\u9010\u884c\u6aa2\u7d22\u6578\u64da\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u65b9\u6cd5\u4f86\u904d\u6b77\u67e5\u8a62\u7d50\u679c\uff0c\u4e26\u5c0d\u6bcf\u4e00\u884c\u6578\u64da\u9032\u884c\u64cd\u4f5c\u3002\u6e38\u6a19\u901a\u5e38\u7528\u65bc\u9700\u8981\u9010\u884c\u8655\u7406\u7684\u60c5\u6cc1\uff0c\u4f8b\u5982\u5728\u6578\u64da\u9077\u79fb\u3001\u5831\u544a\u751f\u6210\u6216\u8907\u96dc\u8a08\u7b97\u4e2d\u3002<\/p>\n<h2 id=\"%e6%b8%b8%e6%a8%99%e7%9a%84%e9%a1%9e%e5%9e%8b-qPyAGWwpQq\">\u6e38\u6a19\u7684\u985e\u578b<\/h2>\n<p>\u6839\u64da\u4e0d\u540c\u7684\u9700\u6c42\uff0c\u6e38\u6a19\u53ef\u4ee5\u5206\u70ba\u5e7e\u7a2e\u985e\u578b\uff1a<\/p>\n<ul>\n<li><strong>\u975c\u614b\u6e38\u6a19\uff1a<\/strong>\u9019\u7a2e\u6e38\u6a19\u5728\u6253\u958b\u6642\u6703\u751f\u6210\u4e00\u500b\u975c\u614b\u7684\u7d50\u679c\u96c6\uff0c\u5f8c\u7e8c\u7684\u6578\u64da\u8b8a\u66f4\u4e0d\u6703\u5f71\u97ff\u5230\u6e38\u6a19\u7684\u5167\u5bb9\u3002<\/li>\n<li><strong>\u52d5\u614b\u6e38\u6a19\uff1a<\/strong>\u52d5\u614b\u6e38\u6a19\u6703\u96a8\u8457\u6578\u64da\u7684\u8b8a\u66f4\u800c\u66f4\u65b0\uff0c\u9019\u610f\u5473\u8457\u5728\u6e38\u6a19\u6253\u958b\u5f8c\uff0c\u4efb\u4f55\u5c0d\u57fa\u790e\u6578\u64da\u7684\u66f4\u6539\u90fd\u6703\u53cd\u6620\u5728\u6e38\u6a19\u4e2d\u3002<\/li>\n<li><strong>\u5feb\u7167\u6e38\u6a19\uff1a<\/strong>\u9019\u7a2e\u6e38\u6a19\u5728\u6253\u958b\u6642\u6703\u6355\u6349\u7576\u524d\u7684\u6578\u64da\u72c0\u614b\uff0c\u4e26\u5728\u6e38\u6a19\u7684\u751f\u547d\u9031\u671f\u5167\u4fdd\u6301\u4e0d\u8b8a\u3002<\/li>\n<li><strong>\u524d\u5411\u6e38\u6a19\uff1a<\/strong>\u9019\u7a2e\u6e38\u6a19\u53ea\u5141\u8a31\u5411\u524d\u904d\u6b77\u7d50\u679c\u96c6\uff0c\u7121\u6cd5\u56de\u5230\u4e4b\u524d\u7684\u884c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b8%b8%e6%a8%99%e7%9a%84%e5%84%aa%e5%8b%a2-qPyAGWwpQq\">\u6e38\u6a19\u7684\u512a\u52e2<\/h2>\n<p>\u4f7f\u7528\u6e38\u6a19\u7684\u4e3b\u8981\u512a\u52e2\u5728\u65bc\u5b83\u80fd\u5920\u63d0\u9ad8\u6578\u64da\u8a2a\u554f\u7684\u9748\u6d3b\u6027\u548c\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u9ad4\u7684\u512a\u52e2\uff1a<\/p>\n<ul>\n<li><strong>\u9010\u884c\u8655\u7406\uff1a<\/strong>\u6e38\u6a19\u5141\u8a31\u958b\u767c\u8005\u9010\u884c\u6aa2\u7d22\u548c\u8655\u7406\u6578\u64da\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u9032\u884c\u8907\u96dc\u8a08\u7b97\u6216\u6578\u64da\u8f49\u63db\u7684\u60c5\u6cc1\u7279\u5225\u6709\u7528\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u5167\u5b58\u4f7f\u7528\uff1a<\/strong>\u5728\u8655\u7406\u5927\u578b\u6578\u64da\u96c6\u6642\uff0c\u6e38\u6a19\u53ef\u4ee5\u6e1b\u5c11\u4e00\u6b21\u6027\u52a0\u8f09\u6240\u6709\u6578\u64da\u5230\u5167\u5b58\u4e2d\u7684\u9700\u6c42\uff0c\u5f9e\u800c\u964d\u4f4e\u5167\u5b58\u4f7f\u7528\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u6027\u80fd\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528\u6e38\u6a19\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\uff0c\u7279\u5225\u662f\u7576\u9700\u8981\u5c0d\u7d50\u679c\u96c6\u9032\u884c\u591a\u6b21\u64cd\u4f5c\u6642\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b8%b8%e6%a8%99%e7%9a%84%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-qPyAGWwpQq\">\u6e38\u6a19\u7684\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528\u6e38\u6a19\u7684\u7c21\u55ae\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728SQL\u4e2d\u5275\u5efa\u548c\u4f7f\u7528\u6e38\u6a19\uff1a<\/p>\n<pre><code>\nDECLARE @EmployeeID INT\nDECLARE EmployeeCursor CURSOR FOR\nSELECT EmployeeID FROM Employees WHERE Department = 'Sales'\n\nOPEN EmployeeCursor\nFETCH NEXT FROM EmployeeCursor INTO @EmployeeID\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n    PRINT 'Processing Employee ID: ' + CAST(@EmployeeID AS VARCHAR)\n    FETCH NEXT FROM EmployeeCursor INTO @EmployeeID\nEND\n\nCLOSE EmployeeCursor\nDEALLOCATE EmployeeCursor\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u6e38\u6a19\u4f86\u9078\u64c7\u92b7\u552e\u90e8\u9580\u7684\u6240\u6709\u54e1\u5de5ID\uff0c\u7136\u5f8c\u9010\u884c\u8655\u7406\u6bcf\u500b\u54e1\u5de5ID\u3002<\/p>\n<h2 id=\"%e6%b8%b8%e6%a8%99%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-qPyAGWwpQq\">\u6e38\u6a19\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5118\u7ba1\u6e38\u6a19\u6709\u5176\u512a\u52e2\uff0c\u4f46\u5728\u4f7f\u7528\u6642\u4e5f\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u5f71\u97ff\uff1a<\/strong>\u904e\u5ea6\u4f7f\u7528\u6e38\u6a19\u53ef\u80fd\u6703\u5c0e\u81f4\u6027\u80fd\u4e0b\u964d\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u3002\u61c9\u8a72\u8b39\u614e\u4f7f\u7528\uff0c\u4e26\u8003\u616e\u5176\u4ed6\u66ff\u4ee3\u65b9\u6848\uff0c\u5982\u6279\u91cf\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u7ba1\u7406\uff1a<\/strong>\u6e38\u6a19\u5728\u4f7f\u7528\u5f8c\u5fc5\u9808\u6b63\u78ba\u95dc\u9589\u548c\u91cb\u653e\uff0c\u4ee5\u907f\u514d\u8cc7\u6e90\u6cc4\u6f0f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-qPyAGWwpQq\">\u7e3d\u7d50<\/h2>\n<p>\u6e38\u6a19\u5728\u6578\u64da\u5eab\u64cd\u4f5c\u4e2d\u626e\u6f14\u8457\u91cd\u8981\u89d2\u8272\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u9010\u884c\u8655\u7406\u6578\u64da\u7684\u60c5\u6cc1\u4e0b\u3002\u901a\u904e\u5408\u7406\u4f7f\u7528\u6e38\u6a19\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u512a\u5316\u6578\u64da\u8a2a\u554f\u901f\u5ea6\uff0c\u63d0\u5347\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u7136\u800c\uff0c\u958b\u767c\u8005\u5728\u4f7f\u7528\u6e38\u6a19\u6642\u4e5f\u61c9\u8a72\u6ce8\u610f\u5176\u6f5b\u5728\u7684\u6027\u80fd\u5f71\u97ff\u548c\u8cc7\u6e90\u7ba1\u7406\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u81f3\u95dc\u91cd\u8981\u3002\u4e86\u89e3\u6e38\u6a19\u7684\u4f7f\u7528\u548c\u512a\u5316\u6280\u5de7\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u8a2d\u8a08\u548c\u5be6\u73fe\u6578\u64da\u5eab\u61c9\u7528\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u6578\u64da\u5eabcursor\u5982\u4f55\u63d0\u5347\u6578\u64da\u8a2a\u554f\u901f\u5ea6\uff0c\u512a\u5316\u67e5\u8a62\u6548\u7387\uff0c\u4e26\u6539\u5584\u6574\u9ad4\u6578\u64da\u8655\u7406\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-185950","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185950","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=185950"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185950\/revisions"}],"predecessor-version":[{"id":185951,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185950\/revisions\/185951"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=185950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=185950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=185950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}