{"id":4984,"date":"2024-11-14T09:43:22","date_gmt":"2024-11-14T01:43:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4984\/"},"modified":"2024-11-14T09:43:22","modified_gmt":"2024-11-14T01:43:22","slug":"oracle%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4%e9%87%8d%e5%a4%8d%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4984\/","title":{"rendered":"oracle\u600e\u4e48\u5220\u9664\u91cd\u590d\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  oracle \u63d0\u4f9b\u4e86\u4e09\u79cd\u5220\u9664\u91cd\u590d\u6570\u636e\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 delete \u8bed\u53e5\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u4fdd\u7559\u6bcf\u7ec4\u4e2d rowid \u6700\u5c0f\u7684\u884c\u3002\u4f7f\u7528 merge \u8bed\u53e5\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u4f7f\u7528 merge \u8bed\u53e5\u5339\u914d\u6e90\u8868\u548c\u76ee\u6807\u8868\u4e2d\u7684\u884c\uff0c\u5e76\u5220\u9664\u91cd\u590d\u884c\u3002\u4f7f\u7528 distinct \u5b50\u67e5\u8be2\u9009\u62e9\u552f\u4e00\u884c\u7684\u96c6\u5408\uff0c\u7136\u540e\u5c06\u5176\u4e0e\u4e3b\u8868\u8fdb\u884c\u6bd4\u8f83\uff0c\u5220\u9664\u4e0d\u5728\u552f\u4e00\u96c6\u5408\u4e2d\u7684\u884c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052108241829592.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u5220\u9664\u91cd\u590d\u6570\u636e\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u5220\u9664\u91cd\u590d\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u5220\u9664\u91cd\u590d\u6570\u636e<\/strong><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 Oracle \u4e2d\u7684\u91cd\u590d\u6570\u636e\uff1f<\/strong><\/p>\n<p>Oracle \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5220\u9664\u91cd\u590d\u6570\u636e\uff0c\u5177\u4f53\u65b9\u6cd5\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u5177\u4f53\u60c5\u51b5\uff1a<\/p>\n<p><strong>1. DELETE \u8bed\u53e5<\/strong><\/p>\n<pre>DELETE FROM table_name\nWHERE rowid NOT IN (SELECT MIN(rowid) FROM table_name GROUP BY column1, column2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65b9\u6cd5\u5148\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u7136\u540e\u53ea\u4fdd\u7559\u6bcf\u7ec4\u4e2d rowid \u6700\u5c0f\u7684\u884c\uff0c\u5220\u9664\u5176\u4ed6\u91cd\u590d\u884c\u3002<\/p>\n<p><strong>2. MERGE \u8bed\u53e5<\/strong><\/p>\n<pre>MERGE INTO table_name AS target\nUSING (SELECT MIN(rowid) AS rowid, column1, column2, ... FROM table_name GROUP BY column1, column2, ...) AS source\nON (target.column1 = source.column1 AND target.column2 = source.column2 AND ...)\nWHEN MATCHED THEN DELETE;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65b9\u6cd5\u4e5f\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u4f46\u5b83\u4f7f\u7528 MERGE \u8bed\u53e5\u6765\u5220\u9664\u91cd\u590d\u884c\uff0c\u8be5\u8bed\u53e5\u5c06\u6e90\u8868\u4e2d\u7684\u884c\u4e0e\u76ee\u6807\u8868\u4e2d\u7684\u884c\u8fdb\u884c\u5339\u914d\uff0c\u5e76\u6839\u636e\u5339\u914d\u6761\u4ef6\u6267\u884c\u5220\u9664\u64cd\u4f5c\u3002<\/p>\n<p><strong>3. DISTINCT \u5b50\u67e5\u8be2<\/strong><\/p>\n<pre>DELETE FROM table_name\nWHERE (column1, column2, ...) NOT IN (SELECT DISTINCT column1, column2, ... FROM table_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65b9\u6cd5\u4f7f\u7528 DISTINCT \u5b50\u67e5\u8be2\u6765\u9009\u62e9\u552f\u4e00\u884c\u7684\u96c6\u5408\uff0c\u7136\u540e\u5c06\u5176\u4e0e\u4e3b\u8868\u8fdb\u884c\u6bd4\u8f83\uff0c\u5220\u9664\u4e0d\u5728\u552f\u4e00\u96c6\u5408\u4e2d\u7684\u884c\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u6267\u884c\u5220\u9664\u64cd\u4f5c\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u5bf9\u6570\u636e\u8fdb\u884c\u4e86\u5907\u4efd\u3002<\/li>\n<li>\u4f7f\u7528 rowid \u5220\u9664\u91cd\u590d\u884c\u53ef\u4ee5\u786e\u4fdd\u5220\u9664\u6240\u6709\u91cd\u590d\u884c\uff0c\u800c\u4e0d\u7ba1\u5217\u503c\u662f\u5426\u76f8\u540c\u3002<\/li>\n<li>\u8fd9\u4e9b\u65b9\u6cd5\u4ec5\u9002\u7528\u4e8e\u4e3b\u952e\u6216\u552f\u4e00\u7d22\u5f15\u4e0d\u5b58\u5728\u6216\u4e0d\u53ef\u7528\u7684\u60c5\u51b5\u3002<\/li>\n<li>\u5982\u679c\u8868\u4e2d\u6709\u5927\u91cf\u91cd\u590d\u6570\u636e\uff0c\u6267\u884c\u5220\u9664\u64cd\u4f5c\u53ef\u80fd\u4f1a\u82b1\u8d39\u5927\u91cf\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5220\u9664\u91cd\u590d\u6570\u636e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>oracle \u63d0\u4f9b\u4e86\u4e09\u79cd\u5220\u9664\u91cd\u590d\u6570\u636e\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 delete \u8bed\u53e5\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u4fdd\u7559\u6bcf\u7ec4\u4e2d rowid \u6700\u5c0f\u7684\u884c\u3002\u4f7f\u7528 merge \u8bed\u53e5\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u4f7f\u7528 merge \u8bed\u53e5\u5339\u914d\u6e90\u8868\u548c\u76ee\u6807\u8868\u4e2d\u7684\u884c\uff0c\u5e76\u5220\u9664\u91cd\u590d\u884c\u3002\u4f7f\u7528 distinct \u5b50\u67e5\u8be2\u9009\u62e9\u552f\u4e00\u884c\u7684\u96c6\u5408\uff0c\u7136\u540e\u5c06\u5176\u4e0e\u4e3b\u8868\u8fdb\u884c\u6bd4\u8f83\uff0c\u5220\u9664\u4e0d\u5728\u552f\u4e00\u96c6\u5408\u4e2d\u7684\u884c\u3002 Oracle \u5220\u9664\u91cd\u590d\u6570\u636e \u5982\u4f55\u5220\u9664 Oracle \u4e2d\u7684\u91cd\u590d\u6570\u636e\uff1f Oracle \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5220\u9664\u91cd\u590d\u6570\u636e\uff0c\u5177\u4f53\u65b9\u6cd5\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u5177\u4f53\u60c5\u51b5\uff1a 1. DELETE \u8bed\u53e5 DELETE FROM table_name WHERE rowid NOT IN (SELECT MIN(rowid) FROM table_name GROUP BY column1, column2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 \u6b64\u65b9\u6cd5\u5148\u6839\u636e\u6307\u5b9a\u5217\u5206\u7ec4\uff0c\u7136\u540e\u53ea\u4fdd\u7559\u6bcf\u7ec4\u4e2d rowid \u6700\u5c0f\u7684\u884c\uff0c\u5220\u9664\u5176\u4ed6\u91cd\u590d\u884c\u3002 2. MERGE \u8bed\u53e5 MERGE INTO table_name AS target USING (SELECT MIN(rowid) AS rowid, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-4984","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=4984"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4984\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}