{"id":193595,"date":"2024-11-12T23:30:21","date_gmt":"2024-11-12T15:30:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/193595\/"},"modified":"2024-11-12T23:30:22","modified_gmt":"2024-11-12T15:30:22","slug":"%e5%ad%b8%e7%bf%92%e6%95%b8%e6%93%9a%e5%ba%ab%e6%b8%b8%e6%a8%99%e7%9a%84%e5%a2%9e%e5%88%aa%e6%93%8d%e4%bd%9c%e6%8a%80%e5%b7%a7-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%b8%b8%e6%a8%99%e5%a2%9e%e5%88%aa","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/193595\/","title":{"rendered":"\u5b78\u7fd2\u6578\u64da\u5eab\u6e38\u6a19\u7684\u589e\u522a\u64cd\u4f5c\u6280\u5de7 (\u6578\u64da\u5eab\u6e38\u6a19\u589e\u522a)"},"content":{"rendered":"<h1 id=\"%e5%ad%b8%e7%bf%92%e6%95%b8%e6%93%9a%e5%ba%ab%e6%b8%b8%e6%a8%99%e7%9a%84%e5%a2%9e%e5%88%aa%e6%93%8d%e4%bd%9c%e6%8a%80%e5%b7%a7-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%b8%b8%e6%a8%99%e5%a2%9e%e5%88%aa-baeNKcgmtK\">\u5b78\u7fd2\u6578\u64da\u5eab\u6e38\u6a19\u7684\u589e\u522a\u64cd\u4f5c\u6280\u5de7 (\u6578\u64da\u5eab\u6e38\u6a19\u589e\u522a)<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u6e38\u6a19\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u9010\u884c\u8655\u7406\u67e5\u8a62\u7d50\u679c\u6642\u3002\u6e38\u6a19\u5141\u8a31\u958b\u767c\u8005\u5728\u6578\u64da\u5eab\u4e2d\u9032\u884c\u66f4\u7d30\u7dfb\u7684\u64cd\u4f5c\uff0c\u5305\u62ec\u589e\u522a\u6578\u64da\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u6578\u64da\u5eab\u6e38\u6a19\u7684\u589e\u522a\u64cd\u4f5c\u6280\u5de7\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u61c9\u7528\u9019\u4e00\u6280\u8853\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%95%b8%e6%93%9a%e5%ba%ab%e6%b8%b8%e6%a8%99%ef%bc%9f-baeNKcgmtK\">\u4ec0\u9ebc\u662f\u6578\u64da\u5eab\u6e38\u6a19\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u6e38\u6a19\u662f\u4e00\u7a2e\u6578\u64da\u5eab\u5c0d\u8c61\uff0c\u5141\u8a31\u7528\u6236\u9010\u884c\u8a2a\u554f\u67e5\u8a62\u7d50\u679c\u96c6\u3002\u6e38\u6a19\u53ef\u4ee5\u88ab\u8996\u70ba\u4e00\u500b\u6307\u91dd\uff0c\u6307\u5411\u67e5\u8a62\u7d50\u679c\u4e2d\u7684\u7576\u524d\u884c\u3002\u4f7f\u7528\u6e38\u6a19\u7684\u4e3b\u8981\u597d\u8655\u662f\u80fd\u5920\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\uff0c\u9010\u884c\u9032\u884c\u64cd\u4f5c\uff0c\u800c\u4e0d\u5fc5\u4e00\u6b21\u6027\u52a0\u8f09\u6240\u6709\u6578\u64da\u3002<\/p>\n<h2 id=\"%e6%b8%b8%e6%a8%99%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c-baeNKcgmtK\">\u6e38\u6a19\u7684\u57fa\u672c\u64cd\u4f5c<\/h2>\n<p>\u5728\u4f7f\u7528\u6e38\u6a19\u9032\u884c\u589e\u522a\u64cd\u4f5c\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3\u6e38\u6a19\u7684\u57fa\u672c\u64cd\u4f5c\uff0c\u5305\u62ec\u8072\u660e\u3001\u6253\u958b\u3001\u63d0\u53d6\u548c\u95dc\u9589\u6e38\u6a19\u3002\u4ee5\u4e0b\u662f\u9019\u4e9b\u64cd\u4f5c\u7684\u7c21\u8981\u4ecb\u7d39\uff1a<\/p>\n<ul>\n<li><strong>\u8072\u660e\u6e38\u6a19\uff1a<\/strong>\u4f7f\u7528 SQL \u8a9e\u53e5\u5b9a\u7fa9\u6e38\u6a19\uff0c\u6307\u5b9a\u8981\u67e5\u8a62\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u6253\u958b\u6e38\u6a19\uff1a<\/strong>\u57f7\u884c\u8072\u660e\u7684 SQL \u67e5\u8a62\uff0c\u4e26\u5c07\u7d50\u679c\u96c6\u8207\u6e38\u6a19\u95dc\u806f\u3002<\/li>\n<li><strong>\u63d0\u53d6\u6578\u64da\uff1a<\/strong>\u4f7f\u7528 FETCH \u8a9e\u53e5\u5f9e\u6e38\u6a19\u4e2d\u63d0\u53d6\u6578\u64da\u3002<\/li>\n<li><strong>\u95dc\u9589\u6e38\u6a19\uff1a<\/strong>\u5728\u64cd\u4f5c\u5b8c\u6210\u5f8c\uff0c\u95dc\u9589\u6e38\u6a19\u4ee5\u91cb\u653e\u8cc7\u6e90\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a2%9e%e5%88%aa%e6%93%8d%e4%bd%9c%e6%8a%80%e5%b7%a7-baeNKcgmtK\">\u589e\u522a\u64cd\u4f5c\u6280\u5de7<\/h2>\n<h3 id=\"%e5%a2%9e%e6%93%8d%e4%bd%9c-baeNKcgmtK\">\u589e\u64cd\u4f5c<\/h3>\n<p>\u5728\u4f7f\u7528\u6e38\u6a19\u9032\u884c\u6578\u64da\u63d2\u5165\u6642\uff0c\u901a\u5e38\u9700\u8981\u5148\u63d0\u53d6\u6578\u64da\uff0c\u7136\u5f8c\u6839\u64da\u63d0\u53d6\u7684\u6578\u64da\u9032\u884c\u63d2\u5165\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>DECLARE @name NVARCHAR(50);\nDECLARE @age INT;\n\nDECLARE my_cursor CURSOR FOR\nSELECT name, age FROM Users;\n\nOPEN my_cursor;\n\nFETCH NEXT FROM my_cursor INTO @name, @age;\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n    INSERT INTO Archive (name, age) VALUES (@name, @age);\n    FETCH NEXT FROM my_cursor INTO @name, @age;\nEND\n\nCLOSE my_cursor;\nDEALLOCATE my_cursor;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u8072\u660e\u4e86\u4e00\u500b\u6e38\u6a19\uff0c\u7136\u5f8c\u5f9e Users \u8868\u4e2d\u63d0\u53d6\u6578\u64da\uff0c\u4e26\u5c07\u5176\u63d2\u5165\u5230 Archive \u8868\u4e2d\u3002\u9019\u7a2e\u65b9\u6cd5\u9069\u5408\u9700\u8981\u6839\u64da\u67e5\u8a62\u7d50\u679c\u9032\u884c\u6279\u91cf\u63d2\u5165\u7684\u60c5\u6cc1\u3002<\/p>\n<h3 id=\"%e5%88%aa%e6%93%8d%e4%bd%9c-baeNKcgmtK\">\u522a\u64cd\u4f5c<\/h3>\n<p>\u522a\u9664\u64cd\u4f5c\u901a\u5e38\u6d89\u53ca\u5230\u6839\u64da\u67d0\u4e9b\u689d\u4ef6\u522a\u9664\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528\u6e38\u6a19\u9032\u884c\u522a\u9664\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>DECLARE @id INT;\n\nDECLARE my_cursor CURSOR FOR\nSELECT id FROM Users WHERE age &gt; 30;\n\nOPEN my_cursor;\n\nFETCH NEXT FROM my_cursor INTO @id;\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n    DELETE FROM Users WHERE id = @id;\n    FETCH NEXT FROM my_cursor INTO @id;\nEND\n\nCLOSE my_cursor;\nDEALLOCATE my_cursor;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9078\u64c7\u4e86\u5e74\u9f61\u5927\u65bc 30 \u7684\u7528\u6236\uff0c\u7136\u5f8c\u9010\u4e00\u522a\u9664\u9019\u4e9b\u7528\u6236\u7684\u8a18\u9304\u3002\u9019\u7a2e\u65b9\u6cd5\u5728\u9700\u8981\u6839\u64da\u7279\u5b9a\u689d\u4ef6\u522a\u9664\u591a\u689d\u8a18\u9304\u6642\u975e\u5e38\u6709\u6548\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-baeNKcgmtK\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528\u6e38\u6a19\u9032\u884c\u589e\u522a\u64cd\u4f5c\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u7279\u5225\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u6e38\u6a19\u7684\u6027\u80fd\uff1a\u6e38\u6a19\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u53ef\u80fd\u6703\u5f71\u97ff\u6027\u80fd\uff0c\u56e0\u6b64\u61c9\u8b39\u614e\u4f7f\u7528\u3002<\/li>\n<li>\u8cc7\u6e90\u7ba1\u7406\uff1a\u78ba\u4fdd\u5728\u64cd\u4f5c\u5b8c\u6210\u5f8c\u95dc\u9589\u548c\u91cb\u653e\u6e38\u6a19\uff0c\u4ee5\u907f\u514d\u8cc7\u6e90\u6d6a\u8cbb\u3002<\/li>\n<li>\u4e8b\u52d9\u63a7\u5236\uff1a\u5728\u9032\u884c\u589e\u522a\u64cd\u4f5c\u6642\uff0c\u8003\u616e\u4f7f\u7528\u4e8b\u52d9\u4f86\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-baeNKcgmtK\">\u7e3d\u7d50<\/h2>\n<p>\u6578\u64da\u5eab\u6e38\u6a19\u7684\u589e\u522a\u64cd\u4f5c\u6280\u5de7\u662f\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u901a\u904e\u6b63\u78ba\u4f7f\u7528\u6e38\u6a19\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u8655\u7406\u6578\u64da\uff0c\u5be6\u73fe\u66f4\u9748\u6d3b\u7684\u6578\u64da\u64cd\u4f5c\u3002\u7121\u8ad6\u662f\u5728\u9032\u884c\u6279\u91cf\u63d2\u5165\u9084\u662f\u6839\u64da\u689d\u4ef6\u522a\u9664\u6578\u64da\uff0c\u6e38\u6a19\u90fd\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u652f\u6301\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\u5834\u666f\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1\u6578\u64da\u5eab\u6e38\u6a19\u7684\u589e\u522a\u64cd\u4f5c\u6280\u5de7\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\uff0c\u7c21\u5316\u6578\u64da\u7ba1\u7406\u6d41\u7a0b\uff0c\u8b93\u6578\u64da\u64cd\u4f5c\u66f4\u6d41\u66a2\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-193595","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/193595","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=193595"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/193595\/revisions"}],"predecessor-version":[{"id":193596,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/193595\/revisions\/193596"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=193595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=193595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=193595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}