{"id":6068,"date":"2024-11-14T08:33:40","date_gmt":"2024-11-14T00:33:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6068\/"},"modified":"2024-11-14T08:33:40","modified_gmt":"2024-11-14T00:33:40","slug":"oracle%e5%a6%82%e4%bd%95%e6%8a%8a%e4%b8%a4%e5%88%97%e5%80%bc%e5%90%88%e5%b9%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6068\/","title":{"rendered":"oracle\u5982\u4f55\u628a\u4e24\u5217\u503c\u5408\u5e76"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u4f7f\u7528 oracle \u5408\u5e76\u4e24\u5217\u503c\uff1f\u4f7f\u7528 || \u64cd\u4f5c\u7b26\u76f4\u63a5\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 concat() \u51fd\u6570\u5408\u5e76\u591a\u4e2a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 case \u8bed\u53e5\u6839\u636e\u6761\u4ef6\u5408\u5e76\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061220422149441.jpg\" class=\"aligncenter\" title=\"oracle\u5982\u4f55\u628a\u4e24\u5217\u503c\u5408\u5e76\u63d2\u56fe\" alt=\"oracle\u5982\u4f55\u628a\u4e24\u5217\u503c\u5408\u5e76\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Oracle \u5408\u5e76\u4e24\u5217\u503c<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u5408\u5e76<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 || \u64cd\u4f5c\u7b26\uff0c\u5c06\u4e24\u5217\u8fde\u63a5\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre>SELECT column1 || column2 FROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u51fd\u6570<\/strong><\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528 CONCAT() \u51fd\u6570\uff0c\u5b83\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u8fde\u63a5\u5728\u4e00\u8d77\uff1a<\/p>\n<pre>SELECT CONCAT(column1, column2) FROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6761\u4ef6<\/strong><\/p>\n<p>\u5982\u679c\u9700\u8981\u6839\u636e\u6761\u4ef6\u5408\u5e76\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 CASE \u8bed\u53e5\uff1a<\/p>\n<pre>SELECT CASE\n    WHEN column1 IS NOT NULL THEN column1\n    WHEN column2 IS NOT NULL THEN column2\n    ELSE NULL  -- \u5982\u679c\u4e24\u5217\u90fd\u4e3a\u7a7a\uff0c\u8fd4\u56de NULL\nEND FROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4ee5\u4e0b\u8868\uff1a<\/p>\n<pre>CREATE TABLE my_table (\n    id INT PRIMARY KEY,\n    first_name VARCHAR(255),\n    last_name VARCHAR(255)\n);\n\nINSERT INTO my_table (id, first_name, last_name) VALUES\n(1, 'John', 'Doe'),\n(2, 'Jane', 'Smith'),\n(3, NULL, 'Wilson');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u76f4\u63a5\u5408\u5e76<\/strong><\/p>\n<pre>SELECT first_name || last_name AS full_name FROM my_table;\n\n+-----------+\n| full_name |\n+-----------+\n| John Doe  |\n| Jane Smith |\n| Wilson    |  -- \u8fd4\u56de NULL\uff0c\u56e0\u4e3a first_name \u4e3a NULL\n+-----------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u51fd\u6570<\/strong><\/p>\n<pre>SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM my_table;\n\n+-----------+\n| full_name |\n+-----------+\n| John Doe  |\n| Jane Smith |\n| NULL Wilson |  -- \u8fd4\u56de NULL\uff0c\u56e0\u4e3a first_name \u4e3a NULL\n+-----------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6761\u4ef6<\/strong><\/p>\n<pre>SELECT CASE\n    WHEN first_name IS NOT NULL THEN first_name\n    WHEN last_name IS NOT NULL THEN last_name\n    ELSE NULL\nEND AS full_name FROM my_table;\n\n+-----------+\n| full_name |\n+-----------+\n| John Doe  |\n| Jane Smith |\n| Wilson    |  -- \u8fd4\u56de \"Wilson\"\uff0c\u56e0\u4e3a last_name \u4e0d\u4e3a\u7a7a\n+-----------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u628a\u4e24\u5217\u503c\u5408\u5e76\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>\u5982\u4f55\u4f7f\u7528 oracle \u5408\u5e76\u4e24\u5217\u503c\uff1f\u4f7f\u7528 || \u64cd\u4f5c\u7b26\u76f4\u63a5\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 concat() \u51fd\u6570\u5408\u5e76\u591a\u4e2a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 case \u8bed\u53e5\u6839\u636e\u6761\u4ef6\u5408\u5e76\u503c\u3002 \u5982\u4f55\u4f7f\u7528 Oracle \u5408\u5e76\u4e24\u5217\u503c \u76f4\u63a5\u5408\u5e76 \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 || \u64cd\u4f5c\u7b26\uff0c\u5c06\u4e24\u5217\u8fde\u63a5\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a SELECT column1 || column2 FROM table_name; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u51fd\u6570 \u4e5f\u53ef\u4ee5\u4f7f\u7528 CONCAT() \u51fd\u6570\uff0c\u5b83\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u8fde\u63a5\u5728\u4e00\u8d77\uff1a SELECT CONCAT(column1, column2) FROM table_name; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u6761\u4ef6 \u5982\u679c\u9700\u8981\u6839\u636e\u6761\u4ef6\u5408\u5e76\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 CASE \u8bed\u53e5\uff1a SELECT CASE WHEN column1 IS NOT NULL THEN column1 WHEN column2 IS NOT NULL THEN column2 ELSE NULL [&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-6068","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6068","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=6068"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6068\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}