{"id":94582,"date":"2024-10-19T19:27:15","date_gmt":"2024-10-19T11:27:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/94582\/"},"modified":"2024-10-19T19:27:15","modified_gmt":"2024-10-19T11:27:15","slug":"oracle-%e6%9f%a5%e8%a9%a2%e5%a6%82%e4%bd%95%e5%81%9a%e5%88%b0-%e5%9b%9b%e5%a4%a7%e7%9a%86%e7%a9%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/94582\/","title":{"rendered":"Oracle \u67e5\u8a62\u5982\u4f55\u505a\u5230 \u201c\u56db\u5927\u7686\u7a7a\u201c"},"content":{"rendered":"<h1 id=\"oracle-%e6%9f%a5%e8%a9%a2%e5%a6%82%e4%bd%95%e5%81%9a%e5%88%b0-%e5%9b%9b%e5%a4%a7%e7%9a%86%e7%a9%ba-lSxbVkBleU\">Oracle \u67e5\u8a62\u5982\u4f55\u505a\u5230 \u201c\u56db\u5927\u7686\u7a7a\u201d<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0cOracle \u662f\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u7cfb\u7d71\uff0c\u5c24\u5176\u662f\u5728\u4f01\u696d\u74b0\u5883\u4e2d\u3002\u7576\u6211\u5011\u8ac7\u5230\u67e5\u8a62\u6642\uff0c\u5e38\u5e38\u6703\u9047\u5230\u9700\u8981\u8fd4\u56de\u7a7a\u7d50\u679c\u96c6\u7684\u60c5\u6cc1\u3002\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u5982\u4f55\u6709\u6548\u5730\u5be6\u73fe\u201c\u56db\u5927\u7686\u7a7a\u201d\u67e5\u8a62\uff0c\u5373\u67e5\u8a62\u7d50\u679c\u4e0d\u5305\u542b\u4efb\u4f55\u6578\u64da\uff0c\u6210\u70ba\u4e86\u8a31\u591a\u958b\u767c\u8005\u9700\u8981\u638c\u63e1\u7684\u6280\u5de7\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%9b%9b%e5%a4%a7%e7%9a%86%e7%a9%ba%e6%9f%a5%e8%a9%a2%ef%bc%9f-lSxbVkBleU\">\u4ec0\u9ebc\u662f\u201c\u56db\u5927\u7686\u7a7a\u201d\u67e5\u8a62\uff1f<\/h2>\n<p>\u201c\u56db\u5927\u7686\u7a7a\u201d\u67e5\u8a62\u662f\u6307\u5728\u57f7\u884c SQL \u67e5\u8a62\u6642\uff0c\u8fd4\u56de\u7684\u7d50\u679c\u96c6\u5b8c\u5168\u6c92\u6709\u6578\u64da\u3002\u9019\u901a\u5e38\u7528\u65bc\u6e2c\u8a66\u3001\u9a57\u8b49\u6216\u5728\u67d0\u4e9b\u696d\u52d9\u908f\u8f2f\u4e2d\u9700\u8981\u78ba\u4fdd\u67e5\u8a62\u4e0d\u8fd4\u56de\u4efb\u4f55\u7d50\u679c\u7684\u60c5\u6cc1\u3002\u9019\u6a23\u7684\u67e5\u8a62\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u78ba\u4fdd\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u6b63\u78ba\u6027\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%be%e5%9b%9b%e5%a4%a7%e7%9a%86%e7%a9%ba%e6%9f%a5%e8%a9%a2-lSxbVkBleU\">\u5982\u4f55\u5be6\u73fe\u201c\u56db\u5927\u7686\u7a7a\u201d\u67e5\u8a62<\/h2>\n<p>\u5728 Oracle \u4e2d\uff0c\u6709\u5e7e\u7a2e\u65b9\u6cd5\u53ef\u4ee5\u5be6\u73fe\u9019\u7a2e\u67e5\u8a62\u3002\u4ee5\u4e0b\u662f\u5e7e\u500b\u5e38\u898b\u7684\u5be6\u73fe\u65b9\u5f0f\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-where-%e5%ad%90%e5%8f%a5-lSxbVkBleU\">1. \u4f7f\u7528 WHERE \u5b50\u53e5<\/h3>\n<p>\u6700\u7c21\u55ae\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u4e00\u500b\u4e0d\u53ef\u80fd\u70ba\u771f\u7684\u689d\u4ef6\u3002\u4f8b\u5982\uff0c\u67e5\u8a62\u4e00\u500b\u4e0d\u5b58\u5728\u7684 ID\uff1a<\/p>\n<pre><code>SELECT * FROM employees WHERE employee_id = -1;<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u5c07\u8fd4\u56de\u4e00\u500b\u7a7a\u7684\u7d50\u679c\u96c6\uff0c\u56e0\u70ba\u5728\u6b63\u5e38\u60c5\u6cc1\u4e0b\uff0c\u54e1\u5de5 ID \u4e0d\u6703\u662f\u8ca0\u6578\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-union-all-lSxbVkBleU\">2. \u4f7f\u7528 UNION ALL<\/h3>\n<p>\u53e6\u4e00\u7a2e\u65b9\u6cd5\u662f\u4f7f\u7528 UNION ALL \u7d50\u5408\u4e00\u500b\u7a7a\u7684\u67e5\u8a62\uff1a<\/p>\n<pre><code>SELECT * FROM employees WHERE 1 = 0 UNION ALL SELECT * FROM dual WHERE 1 = 0;<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u6703\u8fd4\u56de\u7a7a\u7d50\u679c\u96c6\uff0c\u56e0\u70ba\u5169\u500b\u67e5\u8a62\u7684\u689d\u4ef6\u90fd\u4e0d\u6210\u7acb\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-null-%e5%80%bc-lSxbVkBleU\">3. \u4f7f\u7528 NULL \u503c<\/h3>\n<p>\u53ef\u4ee5\u901a\u904e\u67e5\u8a62\u4e00\u500b NULL \u503c\u4f86\u5be6\u73fe\uff1a<\/p>\n<pre><code>SELECT * FROM employees WHERE employee_id IS NULL;<\/code><\/pre>\n<p>\u5982\u679c\u5728\u8868\u4e2d\u6c92\u6709\u4efb\u4f55\u54e1\u5de5\u7684 ID \u70ba NULL\uff0c\u5247\u9019\u500b\u67e5\u8a62\u4e5f\u6703\u8fd4\u56de\u7a7a\u7d50\u679c\u96c6\u3002<\/p>\n<h3 id=\"4-%e4%bd%bf%e7%94%a8%e5%ad%90%e6%9f%a5%e8%a9%a2-lSxbVkBleU\">4. \u4f7f\u7528\u5b50\u67e5\u8a62<\/h3>\n<p>\u5b50\u67e5\u8a62\u4e5f\u662f\u4e00\u500b\u6709\u6548\u7684\u65b9\u5f0f\uff0c\u901a\u904e\u67e5\u8a62\u4e00\u500b\u4e0d\u53ef\u80fd\u7684\u689d\u4ef6\u4f86\u5be6\u73fe\uff1a<\/p>\n<pre><code>SELECT * FROM employees WHERE employee_id IN (SELECT employee_id FROM employees WHERE 1 = 0);<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u6703\u8fd4\u56de\u7a7a\u7d50\u679c\u96c6\uff0c\u56e0\u70ba\u5b50\u67e5\u8a62\u4e0d\u6703\u8fd4\u56de\u4efb\u4f55\u6578\u64da\u3002<\/p>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-lSxbVkBleU\">\u5be6\u969b\u61c9\u7528\u5834\u666f<\/h2>\n<p>\u9019\u4e9b\u201c\u56db\u5927\u7686\u7a7a\u201d\u67e5\u8a62\u7684\u6280\u8853\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u6709\u591a\u7a2e\u7528\u9014\u3002\u4f8b\u5982\uff0c\u5728\u958b\u767c\u904e\u7a0b\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u80fd\u9700\u8981\u6e2c\u8a66\u67d0\u4e9b\u529f\u80fd\u662f\u5426\u80fd\u6b63\u78ba\u8655\u7406\u7a7a\u7d50\u679c\u96c6\u3002\u6b64\u5916\uff0c\u5728\u5831\u544a\u751f\u6210\u6216\u6578\u64da\u5206\u6790\u4e2d\uff0c\u78ba\u4fdd\u67e5\u8a62\u4e0d\u8fd4\u56de\u4efb\u4f55\u6578\u64da\u4e5f\u53ef\u4ee5\u5e6b\u52a9\u8b58\u5225\u6f5b\u5728\u7684\u554f\u984c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-lSxbVkBleU\">\u7e3d\u7d50<\/h2>\n<p>\u5728 Oracle \u6578\u64da\u5eab\u4e2d\uff0c\u5be6\u73fe\u201c\u56db\u5927\u7686\u7a7a\u201d\u67e5\u8a62\u7684\u65b9\u6cd5\u591a\u7a2e\u591a\u6a23\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u65b9\u5f0f\u3002\u7121\u8ad6\u662f\u4f7f\u7528\u4e0d\u53ef\u80fd\u7684\u689d\u4ef6\u3001UNION ALL\u3001NULL \u503c\u9084\u662f\u5b50\u67e5\u8a62\uff0c\u9019\u4e9b\u6280\u8853\u90fd\u80fd\u6709\u6548\u5730\u8fd4\u56de\u7a7a\u7d50\u679c\u96c6\u3002\u638c\u63e1\u9019\u4e9b\u6280\u5de7\u4e0d\u50c5\u80fd\u63d0\u9ad8\u67e5\u8a62\u7684\u9748\u6d3b\u6027\uff0c\u9084\u80fd\u589e\u5f37\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\u6709\u8208\u8da3\uff0c\u6216\u60f3\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a> \u7684\u8cc7\u8a0a\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Oracle\u67e5\u8a62\u6280\u5de7\uff0c\u5b78\u7fd2\u5982\u4f55\u5be6\u73fe\u201c\u56db\u5927\u7686\u7a7a\u201d\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\uff0c\u512a\u5316\u67e5\u8a62\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-94582","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94582","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=94582"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94582\/revisions"}],"predecessor-version":[{"id":94583,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94582\/revisions\/94583"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=94582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=94582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=94582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}