{"id":5996,"date":"2021-05-18T13:58:43","date_gmt":"2021-05-18T05:58:43","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=5996"},"modified":"2021-05-18T13:58:43","modified_gmt":"2021-05-18T05:58:43","slug":"gbase-8a%e9%87%8c%e9%9d%a2null%e5%b8%b8%e9%87%8f%e6%95%b0%e6%8d%ae%e7%9a%84%e7%b1%bb%e5%9e%8b%e6%8c%87%e5%ae%9a%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/5996","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u91cc\u9762null\u5e38\u91cf\u6570\u636e\u7684\u7c7b\u578b\u6307\u5b9a\u65b9\u6cd5"},"content":{"rendered":"<p>GBase 8a\u91cc\uff0cnull\u5e38\u91cf\u6570\u636e\uff0c\u6ce8\u610f\u4e0d\u662f\u67d0\u4e2a\u5b57\u6bb5\u7684\u6570\u503c\u4e3anull,\u800c\u662f\u4e00\u4e2anull\u5e38\u91cf\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\u7c7b\u578b\uff0c\u9ed8\u8ba4\u672avarbinary\u3002\u53ef\u4ee5\u901a\u8fc7cast\u5f3a\u5236\u6307\u5b9a\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u4e0a\u4e0b\u6587\uff0c\u4ece\u5176\u5b83\u5bf9\u5e94\u5b57\u6bb5\u53d6\u5f97\u7c7b\u578b\uff0c\u6bd4\u5982union\u7684\u5176\u5b83\u8868\u7684\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2aea233b0b1\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2aea233b0b1\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/5996\/#%E9%AA%8C%E8%AF%81%E7%8E%AF%E5%A2%83\" >\u9a8c\u8bc1\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/5996\/#%E4%B8%8D%E6%8C%87%E5%AE%9Anull%E5%B8%B8%E9%87%8F%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%88%99%E9%BB%98%E8%AE%A4%E4%B8%BAvarbinary\" >\u4e0d\u6307\u5b9anull\u5e38\u91cf\u7c7b\u578b\uff0c\u5219\u9ed8\u8ba4\u4e3avarbinary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/5996\/#%E9%80%9A%E8%BF%87cast%E5%BC%BA%E5%88%B6%E6%8C%87%E5%AE%9Anull%E7%9A%84%E7%B1%BB%E5%9E%8B\" >\u901a\u8fc7cast\u5f3a\u5236\u6307\u5b9anull\u7684\u7c7b\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/5996\/#2%E8%A1%A8union%E6%97%B6%E5%85%B6%E4%B8%AD%E4%B8%80%E4%B8%AA%E5%8C%85%E5%90%AB%E4%BA%86%E6%98%8E%E7%A1%AE%E7%B1%BB%E5%9E%8B%E6%97%B6%E5%8F%AF%E4%BB%A5%E6%AD%A3%E7%A1%AE%E8%AF%86%E5%88%AB\" >2\u8868union\u65f6\u5176\u4e2d\u4e00\u4e2a\u5305\u542b\u4e86\u660e\u786e\u7c7b\u578b\u65f6\u53ef\u4ee5\u6b63\u786e\u8bc6\u522b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/5996\/#%E5%A4%9A%E8%A1%A8union%E6%97%B6%E5%AF%B9%E5%BA%94%E5%88%97%E7%9A%84%E7%B1%BB%E5%9E%8B%E5%BF%85%E9%A1%BB%E4%B8%80%E8%87%B4\" >\u591a\u8868union\u65f6\u5bf9\u5e94\u5217\u7684\u7c7b\u578b\u5fc5\u987b\u4e00\u81f4<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%AA%8C%E8%AF%81%E7%8E%AF%E5%A2%83\"><\/span>\u9a8c\u8bc1\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>tt1\u8868\u662f\u4e00\u4e2aid int\u7c7b\u578b\u7684\u8868\uff0c\u5c31\u8fd9\u4e00\u4e2a\u5b57\u6bb5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> desc tt1;\r\n+-------+---------+------+-----+---------+-------+\r\n| Field | Type    | Null | Key | Default | Extra |\r\n+-------+---------+------+-----+---------+-------+\r\n| id    | int(11) | YES  |     | NULL    |       |\r\n+-------+---------+------+-----+---------+-------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<p>tt2\u8868\u662f2\u4e2a\u5b57\u6bb5\u7684\u8868\uff0c\u591a\u4e86\u4e00\u4e2avarchar\u7c7b\u578b\u7684name\u5b57\u6bb5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> desc tt2;\r\n+-------+--------------+------+-----+---------+-------+\r\n| Field | Type         | Null | Key | Default | Extra |\r\n+-------+--------------+------+-----+---------+-------+\r\n| id    | int(11)      | YES  |     | NULL    |       |\r\n| name  | varchar(100) | YES  |     | NULL    |       |\r\n+-------+--------------+------+-----+---------+-------+\r\n2 rows in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<p>tt3\u4e5f\u662f2\u4e2a\u5b57\u6bb5\uff0c\u4f46name\u5b57\u6bb5\u6545\u610f\u8bbe\u7f6e\u6210bigint\u7c7b\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table tt3(id int, name bigint);\r\nQuery OK, 0 rows affected (Elapsed: 00:00:00.25)\r\n\r\ngbase> insert into tt3 values(1,111);\r\nQuery OK, 1 row affected (Elapsed: 00:00:00.19)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%B8%8D%E6%8C%87%E5%AE%9Anull%E5%B8%B8%E9%87%8F%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%88%99%E9%BB%98%E8%AE%A4%E4%B8%BAvarbinary\"><\/span>\u4e0d\u6307\u5b9anull\u5e38\u91cf\u7c7b\u578b\uff0c\u5219\u9ed8\u8ba4\u4e3avarbinary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5982\u4e0b\u7684tt2\u8868\uff0c\u7528 null \u751f\u6210name\u5b57\u6bb5\uff0c\u56e0\u4e3a\u6ca1\u6709\u6307\u5b9a\u7c7b\u578b\uff0c\u5219\u9ed8\u8ba4\u662fvarbinary\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table tt6 as select id,null name from tt1;\r\nQuery OK, 9 rows affected (Elapsed: 00:00:01.18)\r\n\r\ngbase> desc tt6;\r\n+-------+--------------+------+-----+---------+-------+\r\n| Field | Type         | Null | Key | Default | Extra |\r\n+-------+--------------+------+-----+---------+-------+\r\n| id    | int(11)      | YES  |     | NULL    |       |\r\n| name  | varbinary(1) | YES  |     | NULL    |       |\r\n+-------+--------------+------+-----+---------+-------+\r\n2 rows in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%80%9A%E8%BF%87cast%E5%BC%BA%E5%88%B6%E6%8C%87%E5%AE%9Anull%E7%9A%84%E7%B1%BB%E5%9E%8B\"><\/span>\u901a\u8fc7cast\u5f3a\u5236\u6307\u5b9anull\u7684\u7c7b\u578b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table tt8 select id,cast(null as int) name from tt1;\r\nQuery OK, 9 rows affected (Elapsed: 00:00:00.56)\r\n\r\ngbase> desc tt8;\r\n+-------+-----------+------+-----+---------+-------+\r\n| Field | Type      | Null | Key | Default | Extra |\r\n+-------+-----------+------+-----+---------+-------+\r\n| id    | int(11)   | YES  |     | NULL    |       |\r\n| name  | bigint(1) | YES  |     | NULL    |       |\r\n+-------+-----------+------+-----+---------+-------+\r\n2 rows in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2%E8%A1%A8union%E6%97%B6%E5%85%B6%E4%B8%AD%E4%B8%80%E4%B8%AA%E5%8C%85%E5%90%AB%E4%BA%86%E6%98%8E%E7%A1%AE%E7%B1%BB%E5%9E%8B%E6%97%B6%E5%8F%AF%E4%BB%A5%E6%AD%A3%E7%A1%AE%E8%AF%86%E5%88%AB\"><\/span>2\u8868union\u65f6\u5176\u4e2d\u4e00\u4e2a\u5305\u542b\u4e86\u660e\u786e\u7c7b\u578b\u65f6\u53ef\u4ee5\u6b63\u786e\u8bc6\u522b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u867d\u7136\u5e26null\u5e38\u91cf\u7684tt1\u5728union\u7684\u524d\u9762\uff0c\u4f46\u7ed3\u679c\u4f9d\u7136\u6b63\u786e\u8bc6\u522b\u4e86\u7c7b\u578b\u4e3att2\u7684varchar\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table tt4 as select id,null name from tt1 union all select * from tt2;\r\nQuery OK, 18 rows affected (Elapsed: 00:00:00.63)\r\n\r\ngbase> desc tt4;\r\n+-------+--------------+------+-----+---------+-------+\r\n| Field | Type         | Null | Key | Default | Extra |\r\n+-------+--------------+------+-----+---------+-------+\r\n| id    | int(11)      | YES  |     | NULL    |       |\r\n| name  | varchar(100) | YES  |     | NULL    |       |\r\n+-------+--------------+------+-----+---------+-------+\r\n2 rows in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%A4%9A%E8%A1%A8union%E6%97%B6%E5%AF%B9%E5%BA%94%E5%88%97%E7%9A%84%E7%B1%BB%E5%9E%8B%E5%BF%85%E9%A1%BB%E4%B8%80%E8%87%B4\"><\/span>\u591a\u8868union\u65f6\u5bf9\u5e94\u5217\u7684\u7c7b\u578b\u5fc5\u987b\u4e00\u81f4<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5982\u679c\u4e0d\u4e00\u81f4\uff0c\u5219\u4f1a\u62a5\u9519\uff0c\u6bd4\u5982\u5982\u4e0b\u7b2c3\u4e2a\u8868tt3\u662fbigint\u7c7b\u578b\uff0c\u7b2c2\u4e2a\u8868tt2\u662fvarchar\u7c7b\u578b\uff0c\u8bed\u53e5\u62a5\u9519\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table tt7 as select id,null name from tt1 union select * from tt2 union all select * from tt3;\r\nERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: UNION\/INTERSECT\/MINUS of non-matching columns: VARCHAR UNION\/INTERSECT\/MINUS LONGLONG\r\n\r\n<\/code><\/pre>\n\n\n\n<p>\u5fc5\u987b\u901a\u8fc7cast\u5f3a\u5236\u8f6c\u5316\u6307\u5b9a\u7c7b\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table tt7 as select id,null name from tt1 union select * from tt2 union all select id,cast(name as char) from tt3;\r\nQuery OK, 17 rows affected (Elapsed: 00:00:00.59)\r\n\r\ngbase> desc tt7;\r\n+-------+--------------+------+-----+---------+-------+\r\n| Field | Type         | Null | Key | Default | Extra |\r\n+-------+--------------+------+-----+---------+-------+\r\n| id    | int(11)      | YES  |     | NULL    |       |\r\n| name  | varchar(100) | YES  |     | NULL    |       |\r\n+-------+--------------+------+-----+---------+-------+\r\n2 rows in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u91cc\uff0cnull\u5e38\u91cf\u6570\u636e\uff0c\u6ce8\u610f\u4e0d\u662f\u67d0\u4e2a\u5b57\u6bb5\u7684\u6570\u503c\u4e3anull,\u800c\u662f\u4e00\u4e2anull\u5e38\u91cf\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\u7c7b\u578b\uff0c\u9ed8\u8ba4\u672avarbinary\u3002\u53ef\u4ee5\u901a\u8fc7cast\u5f3a\u5236\u6307\u5b9a\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u4e0a\u4e0b\u6587\uff0c\u4ece\u5176\u5b83\u5bf9\u5e94\u5b57\u6bb5\u53d6\u5f97\u7c7b\u578b\uff0c\u6bd4\u5982union\u7684\u5176\u5b83\u8868\u7684\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5996","post","type-post","status-publish","format-standard","hentry","category-gbase8a"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=5996"}],"version-history":[{"count":3,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5996\/revisions"}],"predecessor-version":[{"id":5999,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5996\/revisions\/5999"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=5996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=5996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=5996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}