{"id":2660,"date":"2020-12-30T17:36:37","date_gmt":"2020-12-30T09:36:37","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=2660"},"modified":"2020-12-30T17:36:37","modified_gmt":"2020-12-30T09:36:37","slug":"gbase-8a%e7%9a%84decode%e5%87%bd%e6%95%b0%e4%bd%bf%e7%94%a8%e4%be%8b%e5%ad%90","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/2660","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u7684DECODE\u51fd\u6570\u4f7f\u7528\u4f8b\u5b50"},"content":{"rendered":"<p>GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\u652f\u6301decode\u51fd\u6570\uff0c\u7528\u6765\u505a\u6279\u91cf\u5339\u914d\uff0c\u7b80\u5316case when\u7684\u91cd\u590d\u8bed\u6cd5\u3002\u672c\u6587\u4ecb\u7ecd\u51fd\u6570\u7528\u6cd5\u548c\u4e00\u4e9b\u4f7f\u7528\u4f8b\u5b50\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-6a2aced134910\" 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-6a2aced134910\"  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\/2660\/#%E8%AF%AD%E6%B3%95\" >\u8bed\u6cd5<\/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\/2660\/#%E8%AF%B4%E6%98%8E\" >\u8bf4\u660e<\/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\/2660\/#%E6%A0%B7%E4%BE%8B\" >\u6837\u4f8b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/2660\/#%E6%95%B0%E5%80%BC%E6%98%AF%E6%88%90%E5%AF%B9%E5%8C%B9%E9%85%8D%E7%9A%84%EF%BC%8C%E4%B8%94%E6%9C%89%E9%BB%98%E8%AE%A4%E5%80%BC%E3%80%82\" >\u6570\u503c\u662f\u6210\u5bf9\u5339\u914d\u7684\uff0c\u4e14\u6709\u9ed8\u8ba4\u503c\u3002<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/2660\/#%E6%B2%A1%E6%9C%89%E9%BB%98%E8%AE%A4%E5%80%BC\" >\u6ca1\u6709\u9ed8\u8ba4\u503c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gbase8.cn\/en\/2660\/#%E5%8C%B9%E9%85%8DNULL\" >\u5339\u914dNULL<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%AF%AD%E6%B3%95\"><\/span>\u8bed\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>DECODE(value,value1,result1, value2,result2, value3,result3,... , result)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%AF%B4%E6%98%8E\"><\/span>\u8bf4\u660e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u7c7b\u4f3c\u4e8e CASE value WHEN value1 THEN result1 ....\uff0c\u552f\u4e00\u533a\u522b\u662f\u5982\u679c value \u4e3aNULL \u503c\uff0c\u53ef\u4ee5\u548c\u540e\u9762\u7684 NULL \u503c\u5339\u914d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A0%B7%E4%BE%8B\"><\/span>\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%95%B0%E5%80%BC%E6%98%AF%E6%88%90%E5%AF%B9%E5%8C%B9%E9%85%8D%E7%9A%84%EF%BC%8C%E4%B8%94%E6%9C%89%E9%BB%98%E8%AE%A4%E5%80%BC%E3%80%82\"><\/span>\u6570\u503c\u662f\u6210\u5bf9\u5339\u914d\u7684\uff0c\u4e14\u6709\u9ed8\u8ba4\u503c\u3002<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select decode(1,0,'Zero',1,'First',2,'Second','Other');\r\n+-------------------------------------------------+\r\n| decode(1,0,'Zero',1,'First',2,'Second','Other') |\r\n+-------------------------------------------------+\r\n| First                                           |\r\n+-------------------------------------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B2%A1%E6%9C%89%E9%BB%98%E8%AE%A4%E5%80%BC\"><\/span>\u6ca1\u6709\u9ed8\u8ba4\u503c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u4e0d\u5f71\u54cd\u5339\u914d\u7ed3\u679c\uff0c\u4f46\u5219\u4e0d\u5339\u914d\u65f6\u8fd4\u56deNULL<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select decode(1,0,'Zero',1,'First',2,'Second');\r\n+-----------------------------------------+\r\n| decode(1,0,'Zero',1,'First',2,'Second') |\r\n+-----------------------------------------+\r\n| First                                   |\r\n+-----------------------------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n\r\ngbase> select decode(11,0,'Zero',1,'First',2,'Second');\r\n+------------------------------------------+\r\n| decode(11,0,'Zero',1,'First',2,'Second') |\r\n+------------------------------------------+\r\n| NULL                                     |\r\n+------------------------------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8C%B9%E9%85%8DNULL\"><\/span>\u5339\u914dNULL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select decode(null,0,'Zero',1,'First',2,'Second',null,'NULL_VALUE','Other');\r\n+----------------------------------------------------------------------+\r\n| decode(null,0,'Zero',1,'First',2,'Second',null,'NULL_VALUE','Other') |\r\n+----------------------------------------------------------------------+\r\n| NULL_VALUE                                                           |\r\n+----------------------------------------------------------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>\n\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\u652f\u6301decode\u51fd\u6570\uff0c\u7528\u6765\u505a\u6279\u91cf\u5339\u914d\uff0c\u7b80\u5316case when\u7684\u91cd\u590d\u8bed\u6cd5\u3002\u672c\u6587\u4ecb\u7ecd\u51fd\u6570\u7528\u6cd5\u548c\u4e00\u4e9b\u4f7f\u7528\u4f8b\u5b50\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[36],"class_list":["post-2660","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-36"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2660","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=2660"}],"version-history":[{"count":1,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2660\/revisions"}],"predecessor-version":[{"id":2661,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2660\/revisions\/2661"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=2660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=2660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=2660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}