{"id":200160,"date":"2025-05-06T08:20:25","date_gmt":"2025-05-06T00:20:25","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200160\/"},"modified":"2025-05-06T08:20:25","modified_gmt":"2025-05-06T00:20:25","slug":"mysql-%e4%b8%ad%e4%bc%aa%e8%a1%a8-dual-%e7%9a%84%e4%b8%8d%e5%90%8c%e6%9f%a5%e8%af%a2%e6%96%b9%e5%bc%8f%e6%9c%89%e4%bd%95%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200160\/","title":{"rendered":"MySQL \u4e2d\u4f2a\u8868 dual \u7684\u4e0d\u540c\u67e5\u8be2\u65b9\u5f0f\u6709\u4f55\u533a\u522b\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MySQL \u4e2d\u4f2a\u8868 dual \u7684\u4e0d\u540c\u67e5\u8be2\u65b9\u5f0f\u6709\u4f55\u533a\u522b\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6570\u636e\u5e93\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aMySQL \u4e2d\u4f2a\u8868 dual \u7684\u4e0d\u540c\u67e5\u8be2\u65b9\u5f0f\u6709\u4f55\u533a\u522b\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729929660671ca1bcc0314.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u63a2\u7d22 MySQL \u4e2d\u7684\u4f2a\u8868 dual<\/strong><\/p>\n<p><strong>\u4e0d\u540c\u7684\u67e5\u8be2\u65b9\u5f0f<\/strong><\/p>\n<p>\u95ee\u9898\u4e2d\u63d0\u5230\u4e24\u79cd\u67e5\u8be2\u65b9\u5f0f\uff0c\u4e00\u79cd\u4ece\u4f2a\u8868 dual \u4e2d\u67e5\u8be2\uff0c\u53e6\u4e00\u79cd\u76f4\u63a5\u67e5\u8be2\uff1a<\/p>\n<ul>\n<li>select 6+6 from dual;<\/li>\n<li>select 6+6;<\/li>\n<\/ul>\n<p><strong>\u5b83\u4eec\u4e4b\u95f4\u7684\u533a\u522b<\/strong><\/p>\n<p>\u7b54\u6848\u660e\u786e\u6307\u51fa\uff0c\u5728\u8fd9\u4e24\u79cd\u60c5\u51b5\u4e0b\uff0c\u7ed3\u679c\u662f\u6ca1\u6709\u533a\u522b\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u5728 MySQL \u4e2d\uff0cdual \u4f2a\u8868\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u4e34\u65f6\u8868\uff0c\u5b83\u53ea\u6709\u4e00\u884c\u4e00\u5217\uff0c\u5176\u503c\u4e3a NULL\u3002\u5f53\u4ece dual \u4e2d\u67e5\u8be2\u65f6\uff0cMySQL \u57fa\u672c\u4e0a\u5c06\u67e5\u8be2\u8f6c\u6362\u4e3a\u76f4\u63a5\u67e5\u8be2\u3002<\/p>\n<p><strong>MySQL \u4e2d\u4f2a\u8868\u7684\u5e38\u89c1\u573a\u666f<\/strong><\/p>\n<p>\u867d\u7136\u5728 MySQL \u4e2d\u4ece dual \u8868\u4e2d\u67e5\u8be2\u4e0e\u76f4\u63a5\u67e5\u8be2\u6ca1\u6709\u533a\u522b\uff0c\u4f46\u4f2a\u8868\u5728 Oracle \u7b49\u5176\u4ed6\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u5f88\u5e38\u7528\u3002\u5b83\u4eec\u7684\u5e38\u89c1\u573a\u666f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u63d0\u4f9b\u7f3a\u7701\u503c\uff1a<\/strong>dual \u8868\u53ef\u4ee5\u7528\u4e8e\u5728\u67e5\u8be2\u4e2d\u63d0\u4f9b\u7f3a\u7701\u503c\uff0c\u4f8b\u5982 select * from table where field is null or field = (select field from dual) \u4e2d\u7684\u7f3a\u7701\u503c\u3002<\/li>\n<li><strong>\u6a21\u62df\u591a\u884c\u8bb0\u5f55\uff1a<\/strong>\u4f7f\u7528\u7b1b\u5361\u5c14\u79ef\u6216 UNION \u53ef\u4ee5\u5c06\u6765\u81ea dual \u8868\u7684\u5355\u884c\u591a\u6b21\u56de\u6536\u6765\u6a21\u62df\u591a\u884c\u8bb0\u5f55\u3002\u4f8b\u5982\uff0cselect id, name from dual cross join (select id, name from table) \u4f1a\u4ea7\u751f table \u4e2d\u6bcf\u4e2a id \u548c name \u7684\u6240\u6709\u7ec4\u5408\u3002<\/li>\n<li><strong>\u751f\u6210\u5e8f\u5217\uff1a<\/strong>\u901a\u8fc7\u4f7f\u7528 COUNT(*) \u548c UNION \u53ef\u4ee5\u4ece dual \u8868\u4e2d\u751f\u6210\u5e8f\u5217\u3002\u4f8b\u5982\uff0cselect count(*) from dual union all select count(*) from dual &#8230; \u4ea7\u751f\u4e00\u4e2a\u65e0\u7a77\u5e8f\u5217\u3002<\/li>\n<\/ul>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aMySQL \u4e2d\u4f2a\u8868 dual \u7684\u4e0d\u540c\u67e5\u8be2\u65b9\u5f0f\u6709\u4f55\u533a\u522b\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u4e2d\u4f2a\u8868 dual \u7684&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200160","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200160","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200160"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200160\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}