{"id":5188,"date":"2024-11-14T10:39:56","date_gmt":"2024-11-14T02:39:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5188\/"},"modified":"2024-11-14T10:39:56","modified_gmt":"2024-11-14T02:39:56","slug":"sql%e4%b8%adnvl%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5188\/","title":{"rendered":"sql\u4e2dnvl\u7684\u7528\u6cd5"},"content":{"rendered":"<blockquote><p>\n  nvl \u51fd\u6570\u66ff\u6362 sql \u4e2d\u7684 null \u503c\u4e3a\u6307\u5b9a\u503c\uff0c\u89e3\u51b3\u4ee5\u4e0b\u95ee\u9898\uff1a\u907f\u514d null \u5bfc\u81f4\u67e5\u8be2\u9519\u8bef\u3002\u66ff\u6362 null \u4ee5\u8fdb\u884c\u8ba1\u7b97\u548c\u805a\u5408\u3002\u4ee5\u975e\u7a7a\u503c\u586b\u5145 null \u4ee5\u663e\u793a\u3002\u8bed\u6cd5\uff1anvl(expression, replacement_value)\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/24\/2024052419212239457.jpg\" class=\"aligncenter\" title=\"sql\u4e2dnvl\u7684\u7528\u6cd5\u63d2\u56fe\" alt=\"sql\u4e2dnvl\u7684\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>NVL \u51fd\u6570\u5728 SQL \u4e2d\u7684\u7528\u6cd5<\/strong><\/p>\n<p>NVL \u51fd\u6570\u7528\u4e8e\u66ff\u6362 NULL \u503c\u4e3a\u6307\u5b9a\u7684\u975e\u7a7a\u503c\u3002\u5b83\u63a5\u53d7\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>NVL(expression, replacement_value)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>expression\uff1a<\/strong>\u8981\u68c0\u67e5\u662f\u5426\u4e3a NULL \u7684\u8868\u8fbe\u5f0f\u3002<\/li>\n<li> <strong>replacement_value\uff1a<\/strong>\u5f53 expression \u4e3a NULL \u65f6\u8981\u8fd4\u56de\u7684\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>NVL \u51fd\u6570\u53ef\u7528\u4e8e\u89e3\u51b3\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u907f\u514d NULL \u503c\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u51fa\u73b0\u9519\u8bef\u3002<\/li>\n<li>\u5728\u8ba1\u7b97\u548c\u805a\u5408\u4e4b\u524d\u66ff\u6362 NULL \u503c\u3002<\/li>\n<li>\u4ee5\u975e\u7a7a\u503c\u586b\u5145 NULL \u503c\uff0c\u4ee5\u4fbf\u5728\u62a5\u8868\u6216\u7528\u6237\u754c\u9762\u4e2d\u663e\u793a\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>-- \u66ff\u6362 \"name\" \u5217\u4e2d\u7684 NULL \u503c\u4e3a \"Unknown\"\nSELECT NVL(name, 'Unknown') AS full_name FROM table_name;\n\n-- \u8ba1\u7b97 \"sales\" \u5217\u7684\u603b\u548c\uff0c\u5ffd\u7565 NULL \u503c\nSELECT SUM(NVL(sales, 0)) AS total_sales FROM orders;\n\n-- \u5728\u62a5\u8868\u4e2d\u663e\u793a\u975e\u7a7a\u7684 \"address\" \u5217\nSELECT NVL(address, 'No address available') AS address FROM customers;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>replacement_value \u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u4e0d\u5efa\u8bae\u4f7f\u7528\u4e0e expression \u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li>\u5982\u679c expression \u548c replacement_value \u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\uff0c\u5219 NVL \u51fd\u6570\u5c06\u8fd4\u56de NULL\u3002<\/li>\n<li>NVL \u51fd\u6570\u4e0d\u80fd\u7528\u4e8e\u66ff\u6362\u5176\u4ed6\u7279\u6b8a\u503c\uff0c\u5982 NaN \u6216 Infinity\u3002<\/li>\n<li>\u5efa\u8bae\u5728\u4f7f\u7528 NVL \u51fd\u6570\u4e4b\u524d\u68c0\u67e5 NULL \u503c\uff0c\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5f00\u9500\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u4e2dnvl\u7684\u7528\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>nvl \u51fd\u6570\u66ff\u6362 sql \u4e2d\u7684 null \u503c\u4e3a\u6307\u5b9a\u503c\uff0c\u89e3\u51b3\u4ee5\u4e0b\u95ee\u9898\uff1a\u907f\u514d null \u5bfc\u81f4\u67e5\u8be2\u9519\u8bef\u3002\u66ff\u6362 null \u4ee5\u8fdb\u884c\u8ba1\u7b97\u548c\u805a\u5408\u3002\u4ee5\u975e\u7a7a\u503c\u586b\u5145 null \u4ee5\u663e\u793a\u3002\u8bed\u6cd5\uff1anvl(expression, replacement_value) NVL \u51fd\u6570\u5728 SQL \u4e2d\u7684\u7528\u6cd5 NVL \u51fd\u6570\u7528\u4e8e\u66ff\u6362 NULL \u503c\u4e3a\u6307\u5b9a\u7684\u975e\u7a7a\u503c\u3002\u5b83\u63a5\u53d7\u4e09\u4e2a\u53c2\u6570\uff1a \u8bed\u6cd5\uff1a NVL(expression, replacement_value) \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570\uff1a expression\uff1a\u8981\u68c0\u67e5\u662f\u5426\u4e3a NULL \u7684\u8868\u8fbe\u5f0f\u3002 replacement_value\uff1a\u5f53 expression \u4e3a NULL \u65f6\u8981\u8fd4\u56de\u7684\u503c\u3002 \u4f7f\u7528\u65b9\u6cd5\uff1a NVL \u51fd\u6570\u53ef\u7528\u4e8e\u89e3\u51b3\u4ee5\u4e0b\u95ee\u9898\uff1a \u907f\u514d NULL \u503c\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u51fa\u73b0\u9519\u8bef\u3002 \u5728\u8ba1\u7b97\u548c\u805a\u5408\u4e4b\u524d\u66ff\u6362 NULL \u503c\u3002 \u4ee5\u975e\u7a7a\u503c\u586b\u5145 NULL \u503c\uff0c\u4ee5\u4fbf\u5728\u62a5\u8868\u6216\u7528\u6237\u754c\u9762\u4e2d\u663e\u793a\u3002 \u793a\u4f8b\uff1a &#8212; \u66ff\u6362 &#8220;name&#8221; \u5217\u4e2d\u7684 NULL \u503c\u4e3a &#8220;Unknown&#8221; SELECT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5188","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5188"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5188\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}