{"id":5008,"date":"2024-11-14T11:52:07","date_gmt":"2024-11-14T03:52:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5008\/"},"modified":"2024-11-14T11:52:07","modified_gmt":"2024-11-14T03:52:07","slug":"oracle%e6%80%8e%e4%b9%88%e5%8f%96%e6%b6%88%e9%87%8d%e5%a4%8d%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5008\/","title":{"rendered":"oracle\u600e\u4e48\u53d6\u6d88\u91cd\u590d\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  oracle \u4e2d\u53d6\u6d88\u91cd\u590d\u6570\u636e\u7684\u65b9\u6cd5\u6709\uff1a\u521b\u5efa\u552f\u4e00\u6027\u7ea6\u675f\u6216\u4e3b\u952e\uff0c\u4f7f\u7528 merge \u8bed\u53e5\u5408\u5e76\u91cd\u590d\u884c\uff0c\u6216\u4f7f\u7528 delete \u8bed\u53e5\u5220\u9664\u91cd\u590d\u884c\u3002\u8fd9\u4e9b\u65b9\u6cd5\u6709\u52a9\u4e8e\u51cf\u5c11\u5b58\u50a8\u5f00\u9500\u3001\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u5e76\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052110181883021.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u53d6\u6d88\u91cd\u590d\u6570\u636e\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u53d6\u6d88\u91cd\u590d\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u53d6\u6d88 Oracle \u4e2d\u7684\u91cd\u590d\u6570\u636e<\/strong><\/p>\n<p>Oracle \u4e2d\u7684\u91cd\u590d\u6570\u636e\u4f1a\u5bfc\u81f4\u5b58\u50a8\u5f00\u9500\u8fc7\u5927\u3001\u67e5\u8be2\u6548\u7387\u4f4e\u4e0b\uff0c\u751a\u81f3\u4f1a\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\u56e0\u6b64\uff0c\u53d6\u6d88\u91cd\u590d\u6570\u636e\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p><strong>\u53d6\u6d88\u91cd\u590d\u6570\u636e\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><strong>1. \u552f\u4e00\u6027\u7ea6\u675f<\/strong><\/p>\n<p>\u521b\u5efa\u552f\u4e00\u6027\u7ea6\u675f\u662f\u9632\u6b62\u91cd\u590d\u6570\u636e\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u552f\u4e00\u6027\u7ea6\u675f\u5f3a\u5236\u6bcf\u4e2a\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u5177\u6709\u552f\u4e00\u7684\u5217\u6216\u5217\u96c6\u3002<\/p>\n<pre>ALTER TABLE table_name ADD UNIQUE (column_name1, column_name2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. PRIMARY KEY<\/strong><\/p>\n<p>\u4e3b\u952e\u662f\u552f\u4e00\u6027\u7ea6\u675f\u7684\u7279\u6b8a\u60c5\u51b5\uff0c\u5b83\u6307\u5b9a\u8868\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u5217\u4f5c\u4e3a\u552f\u4e00\u6807\u8bc6\u7b26\u3002<\/p>\n<pre>ALTER TABLE table_name ADD PRIMARY KEY (column_name1, column_name2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. MERGE \u8bed\u53e5<\/strong><\/p>\n<p>MERGE \u8bed\u53e5\u53ef\u4ee5\u7528\u6765\u5c06\u91cd\u590d\u7684\u884c\u5408\u5e76\u5230\u540c\u4e00\u884c\u4e2d\u3002\u5b83\u4f7f\u7528 UNION ALL \u6765\u7ec4\u5408\u91cd\u590d\u7684\u884c\uff0c\u7136\u540e\u4f7f\u7528 UPDATE \u8bed\u53e5\u6765\u66f4\u65b0\u76ee\u6807\u8868\u3002<\/p>\n<pre>MERGE INTO target_table AS t\nUSING source_table AS s\nON (t.column_name1 = s.column_name1 AND t.column_name2 = s.column_name2)\nWHEN MATCHED THEN\n  UPDATE SET t.column_name3 = s.column_name3\nWHEN NOT MATCHED THEN\n  INSERT (column_name1, column_name2, column_name3)\n  VALUES (s.column_name1, s.column_name2, s.column_name3);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u5220\u9664\u91cd\u590d\u7684\u884c<\/strong><\/p>\n<p>\u5982\u679c\u4e0d\u9700\u8981\u91cd\u590d\u7684\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528 DELETE \u8bed\u53e5\u5220\u9664\u5b83\u4eec\u3002<\/p>\n<pre>DELETE FROM table_name\nWHERE rowid NOT IN (\n  SELECT MIN(rowid)\n  FROM table_name\n  GROUP BY column_name1, column_name2, ...\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u53d6\u6d88\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 \u4e2d\u53d6\u6d88\u91cd\u590d\u6570\u636e\u7684\u65b9\u6cd5\u6709\uff1a\u521b\u5efa\u552f\u4e00\u6027\u7ea6\u675f\u6216\u4e3b\u952e\uff0c\u4f7f\u7528 merge \u8bed\u53e5\u5408\u5e76\u91cd\u590d\u884c\uff0c\u6216\u4f7f\u7528 delete \u8bed\u53e5\u5220\u9664\u91cd\u590d\u884c\u3002\u8fd9\u4e9b\u65b9\u6cd5\u6709\u52a9\u4e8e\u51cf\u5c11\u5b58\u50a8\u5f00\u9500\u3001\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u5e76\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u3002 \u5982\u4f55\u53d6\u6d88 Oracle \u4e2d\u7684\u91cd\u590d\u6570\u636e Oracle \u4e2d\u7684\u91cd\u590d\u6570\u636e\u4f1a\u5bfc\u81f4\u5b58\u50a8\u5f00\u9500\u8fc7\u5927\u3001\u67e5\u8be2\u6548\u7387\u4f4e\u4e0b\uff0c\u751a\u81f3\u4f1a\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\u56e0\u6b64\uff0c\u53d6\u6d88\u91cd\u590d\u6570\u636e\u975e\u5e38\u91cd\u8981\u3002 \u53d6\u6d88\u91cd\u590d\u6570\u636e\u7684\u6b65\u9aa4\uff1a 1. \u552f\u4e00\u6027\u7ea6\u675f \u521b\u5efa\u552f\u4e00\u6027\u7ea6\u675f\u662f\u9632\u6b62\u91cd\u590d\u6570\u636e\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u552f\u4e00\u6027\u7ea6\u675f\u5f3a\u5236\u6bcf\u4e2a\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u5177\u6709\u552f\u4e00\u7684\u5217\u6216\u5217\u96c6\u3002 ALTER TABLE table_name ADD UNIQUE (column_name1, column_name2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 2. PRIMARY KEY \u4e3b\u952e\u662f\u552f\u4e00\u6027\u7ea6\u675f\u7684\u7279\u6b8a\u60c5\u51b5\uff0c\u5b83\u6307\u5b9a\u8868\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u5217\u4f5c\u4e3a\u552f\u4e00\u6807\u8bc6\u7b26\u3002 ALTER TABLE table_name ADD PRIMARY KEY (column_name1, column_name2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 3. MERGE \u8bed\u53e5 MERGE \u8bed\u53e5\u53ef\u4ee5\u7528\u6765\u5c06\u91cd\u590d\u7684\u884c\u5408\u5e76\u5230\u540c\u4e00\u884c\u4e2d\u3002\u5b83\u4f7f\u7528 UNION ALL \u6765\u7ec4\u5408\u91cd\u590d\u7684\u884c\uff0c\u7136\u540e\u4f7f\u7528 UPDATE \u8bed\u53e5\u6765\u66f4\u65b0\u76ee\u6807\u8868\u3002 MERGE INTO target_table AS t USING source_table [&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-5008","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5008","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=5008"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5008\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}