{"id":2984,"date":"2021-01-07T08:38:11","date_gmt":"2021-01-07T00:38:11","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=2984"},"modified":"2021-01-07T08:38:12","modified_gmt":"2021-01-07T00:38:12","slug":"gbase-8a%e5%88%a4%e6%96%ad%e5%87%bd%e6%95%b0if%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e4%bd%bf%e7%94%a8%e4%be%8b%e5%ad%90","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/2984","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u5224\u65ad\u51fd\u6570IF\u7684\u7528\u6cd5\u548c\u4f7f\u7528\u4f8b\u5b50"},"content":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecdGBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\u63d0\u4f9b\u7684IF\u5224\u65ad\u51fd\u6570\u7684\u8bed\u6cd5\u548c\u4f7f\u7528\u6837\u4f8b\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-6a2b27ba1fcbe\" 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-6a2b27ba1fcbe\"  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\/2984\/#%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\/2984\/#%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\/2984\/#%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\/2984\/#expre1_%E7%9A%84%E5%80%BC%E4%B8%BA_FALSE\" >expre1 \u7684\u503c\u4e3a FALSE<\/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\/2984\/#expre1_%E7%9A%84%E5%80%BC%E4%B8%BA_TRUE\" >expre1 \u7684\u503c\u4e3a TRUE<\/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\/2984\/#expr1_%E4%B8%BA%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%8C%E5%80%BC%E4%B8%BA_TRUE\" >expr1 \u4e3a\u8868\u8fbe\u5f0f\uff0c\u503c\u4e3a TRUE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gbase8.cn\/en\/2984\/#expr1_%E4%B8%BA%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%8C%E5%80%BC%E4%B8%8D%E4%B8%BA_TRUE\" >expr1 \u4e3a\u8868\u8fbe\u5f0f\uff0c\u503c\u4e0d\u4e3a TRUE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.gbase8.cn\/en\/2984\/#exptr%E6%98%AFnull%E5%80%BC\" >exptr\u662fnull\u503c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.gbase8.cn\/en\/2984\/#exptr%E6%98%AF%E7%A9%BA%E5%AD%97%E7%AC%A6%E4%B8%B2\" >exptr\u662f\u7a7a\u5b57\u7b26\u4e32<\/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>IF(expr1,expr2,expr3)<\/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>\u5982\u679c expr1 \u4e3a TRUE \u5219 IF()\u7684\u8fd4\u56de\u503c\u4e3a expr2\uff0c\u5982\u679c expr1 \u53d6\u503c\u4e3a FALSE\u30010 \u6216NULL\uff0c\u5219\u8fd4\u56de\u503c\u4e3a expr3\u3002<br>IF()\u7684\u8fd4\u56de\u503c\u89c4\u5219\u540c CASE \u8868\u8fbe\u5f0f\u8fd4\u56de\u503c\u7684\u89c4\u5219\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=\"expre1_%E7%9A%84%E5%80%BC%E4%B8%BA_FALSE\"><\/span>expre1 \u7684\u503c\u4e3a FALSE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd4\u56de\u503c\u4e3a expr3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> SELECT IF(FALSE,2,3) FROM dual;\r\n+-------------+\r\n| IF(FALSE,2,3) |\r\n+-------------+\r\n| 3 |\r\n+-------------+\r\n1 row in set<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"expre1_%E7%9A%84%E5%80%BC%E4%B8%BA_TRUE\"><\/span>expre1 \u7684\u503c\u4e3a TRUE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd4\u56de\u503c\u4e3a expr2\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> SELECT IF(TRUE,'yes','no') FROM dual;\r\n+--------------------+\r\n| IF(TRUE,'yes','no') |\r\n+--------------------+\r\n| yes |\r\n+--------------------+\r\n1 row in set<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"expr1_%E4%B8%BA%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%8C%E5%80%BC%E4%B8%BA_TRUE\"><\/span>expr1 \u4e3a\u8868\u8fbe\u5f0f\uff0c\u503c\u4e3a TRUE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd4\u56de\u503c\u4e3a expr2\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> SELECT IF(1&lt;2,'no','yes') FROM dual;\r\n+---------------------------------------+\r\n| IF(1&lt;2,'no','yes') |\r\n+---------------------------------------+\r\n| no |\r\n+---------------------------------------+\r\n1 row in set<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"expr1_%E4%B8%BA%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%8C%E5%80%BC%E4%B8%8D%E4%B8%BA_TRUE\"><\/span>expr1 \u4e3a\u8868\u8fbe\u5f0f\uff0c\u503c\u4e0d\u4e3a TRUE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd4\u56de\u503c\u4e3a expr3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> SELECT IF(1>2,NULL,'no') FROM dual;\r\n+-------------------+\r\n| IF(1>2,NULL,'no') |\r\n+-------------------+\r\n| no |\r\n+-------------------+\r\n1 row in set<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"exptr%E6%98%AFnull%E5%80%BC\"><\/span>exptr\u662fnull\u503c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd4\u56deexpr3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select if(null,'NOT_NULL','IS_A_NULL');\r\n+---------------------------------+\r\n| if(null,'NOT_NULL','IS_A_NULL') |\r\n+---------------------------------+\r\n| IS_A_NULL                       |\r\n+---------------------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n\r\ngbase>\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"exptr%E6%98%AF%E7%A9%BA%E5%AD%97%E7%AC%A6%E4%B8%B2\"><\/span>exptr\u662f\u7a7a\u5b57\u7b26\u4e32<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd4\u56deexpr3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select if('','NOT_NULL','IS_A_NULL');\r\n+-------------------------------+\r\n| if('','NOT_NULL','IS_A_NULL') |\r\n+-------------------------------+\r\n| IS_A_NULL                     |\r\n+-------------------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecdGBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\u63d0\u4f9b\u7684IF\u5224\u65ad\u51fd\u6570\u7684\u8bed\u6cd5\u548c\u4f7f\u7528\u6837\u4f8b\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-2984","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\/2984","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=2984"}],"version-history":[{"count":5,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2984\/revisions"}],"predecessor-version":[{"id":2989,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2984\/revisions\/2989"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=2984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=2984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=2984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}