{"id":77990,"date":"2024-10-16T11:24:18","date_gmt":"2024-10-16T03:24:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/77990\/"},"modified":"2024-10-16T11:24:18","modified_gmt":"2024-10-16T03:24:18","slug":"mysql%e6%8c%87%e4%bb%a4-concat%ef%bc%88%e9%80%a3%e6%8e%a5%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/77990\/","title":{"rendered":"MySQL\u6307\u4ee4: CONCAT()\uff08\u9023\u63a5\u5b57\u7b26\u4e32\uff09"},"content":{"rendered":"<h1 id=\"mysql%e6%8c%87%e4%bb%a4-concat%ef%bc%88%e9%80%a3%e6%8e%a5%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%89-eXpSogWMYM\">MySQL\u6307\u4ee4: CONCAT()\uff08\u9023\u63a5\u5b57\u7b26\u4e32\uff09<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c\u662f\u975e\u5e38\u5e38\u898b\u7684\u9700\u6c42\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u51fd\u6578\u4f86\u8655\u7406\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u4e4b\u4e00\u5c31\u662f <code>CONCAT()<\/code> \u51fd\u6578\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e <code>CONCAT()<\/code> \u51fd\u6578\u7684\u7528\u6cd5\u3001\u7279\u6027\u53ca\u5176\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u7684\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-concat-%e5%87%bd%e6%95%b8%ef%bc%9f-eXpSogWMYM\">\u4ec0\u9ebc\u662f CONCAT() \u51fd\u6578\uff1f<\/h2>\n<p><code>CONCAT()<\/code> \u51fd\u6578\u7528\u65bc\u5c07\u5169\u500b\u6216\u591a\u500b\u5b57\u7b26\u4e32\u9023\u63a5\u6210\u4e00\u500b\u5b57\u7b26\u4e32\u3002\u9019\u500b\u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CONCAT(string1, string2, ...)<\/code><\/pre>\n<p>\u5728\u9019\u88e1\uff0c<code>string1<\/code>\u3001<code>string2<\/code> \u7b49\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u6587\u5b57\u3001\u5217\u540d\u6216\u5176\u4ed6\u8868\u9054\u5f0f\u3002\u7576\u51fd\u6578\u88ab\u8abf\u7528\u6642\uff0c\u5b83\u6703\u5c07\u6240\u6709\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u9023\u63a5\u5728\u4e00\u8d77\uff0c\u4e26\u8fd4\u56de\u4e00\u500b\u65b0\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-concat-%e5%87%bd%e6%95%b8%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%a4%ba%e4%be%8b-eXpSogWMYM\">\u4f7f\u7528 CONCAT() \u51fd\u6578\u7684\u57fa\u672c\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 <code>CONCAT()<\/code> \u51fd\u6578\u4f86\u9023\u63a5\u5169\u500b\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code>SELECT CONCAT('Hello', ' ', 'World') AS Greeting;<\/code><\/pre>\n<p>\u57f7\u884c\u4e0a\u8ff0\u67e5\u8a62\u5f8c\uff0c\u7d50\u679c\u5c07\u986f\u793a\u70ba\uff1a<\/p>\n<pre><code>Greeting\n---------\nHello World<\/code><\/pre>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e8%a1%a8%e4%b8%ad%e7%9a%84%e5%88%97-eXpSogWMYM\">\u9023\u63a5\u8868\u4e2d\u7684\u5217<\/h2>\n<p>\u9664\u4e86\u9023\u63a5\u975c\u614b\u5b57\u7b26\u4e32\u5916\uff0c<code>CONCAT()<\/code> \u51fd\u6578\u9084\u53ef\u4ee5\u7528\u4f86\u9023\u63a5\u8868\u4e2d\u7684\u5217\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6709\u4e00\u500b\u540d\u70ba <code>users<\/code> \u7684\u8868\uff0c\u5305\u542b <code>first_name<\/code> \u548c <code>last_name<\/code> \u5169\u500b\u5217\uff0c\u6211\u5011\u53ef\u4ee5\u9019\u6a23\u4f7f\u7528 <code>CONCAT()<\/code>\uff1a<\/p>\n<pre><code>SELECT CONCAT(first_name, ' ', last_name) AS FullName FROM users;<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u5c07\u8fd4\u56de\u6bcf\u500b\u7528\u6236\u7684\u5168\u540d\uff0c\u683c\u5f0f\u70ba\u300c\u540d \u59d3\u300d\u3002<\/p>\n<h2 id=\"%e8%99%95%e7%90%86-null-%e5%80%bc-eXpSogWMYM\">\u8655\u7406 NULL \u503c<\/h2>\n<p>\u5728\u4f7f\u7528 <code>CONCAT()<\/code> \u51fd\u6578\u6642\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u4efb\u4f55\u4e00\u500b\u53c3\u6578\u70ba <code>NULL<\/code>\uff0c\u5247\u8a72\u53c3\u6578\u5c07\u88ab\u8996\u70ba\u7a7a\u5b57\u7b26\u4e32\u3002\u9019\u610f\u5473\u8457\uff1a<\/p>\n<pre><code>SELECT CONCAT('Hello', NULL, 'World') AS Result;<\/code><\/pre>\n<p>\u5c07\u8fd4\u56de\uff1a<\/p>\n<pre><code>Result\n---------\nHelloWorld<\/code><\/pre>\n<p>\u9019\u4e00\u7279\u6027\u4f7f\u5f97 <code>CONCAT()<\/code> \u51fd\u6578\u5728\u8655\u7406\u53ef\u80fd\u5305\u542b\u7a7a\u503c\u7684\u6578\u64da\u6642\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<h2 id=\"%e5%a4%9a%e5%80%8b%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84%e9%80%a3%e6%8e%a5-eXpSogWMYM\">\u591a\u500b\u5b57\u7b26\u4e32\u7684\u9023\u63a5<\/h2>\n<p><code>CONCAT()<\/code> \u51fd\u6578\u53ef\u4ee5\u63a5\u53d7\u591a\u9054 255 \u500b\u53c3\u6578\uff0c\u9019\u4f7f\u5f97\u5b83\u80fd\u5920\u8f15\u9b06\u5730\u9023\u63a5\u591a\u500b\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT CONCAT('My', 'SQL', ' ', 'is', ' ', 'awesome!') AS Statement;<\/code><\/pre>\n<p>\u7d50\u679c\u5c07\u986f\u793a\u70ba\uff1a<\/p>\n<pre><code>Statement\n----------------\nMySQL is awesome!<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-eXpSogWMYM\">\u7d50\u8ad6<\/h2>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0c<code>CONCAT()<\/code> \u51fd\u6578\u662f\u4e00\u500b\u5f37\u5927\u4e14\u9748\u6d3b\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u5728 MySQL \u4e2d\u8f15\u9b06\u5730\u9023\u63a5\u5b57\u7b26\u4e32\u3002\u7121\u8ad6\u662f\u5728\u751f\u6210\u5831\u544a\u3001\u8655\u7406\u7528\u6236\u8f38\u5165\u9084\u662f\u69cb\u5efa\u8907\u96dc\u7684\u67e5\u8a62\uff0c<code>CONCAT()<\/code> \u90fd\u80fd\u63d0\u4f9b\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u65b9\u6848\u53ef\u4ee5\u9032\u4e00\u6b65\u63d0\u5347\u6027\u80fd\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u6d41\u66a2\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MySQL\u6307\u4ee4CONCAT()\uff0c\u8f15\u9b06\u9023\u63a5\u591a\u500b\u5b57\u7b26\u4e32\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\uff0c\u7c21\u5316\u67e5\u8a62\u7d50\u679c\u7684\u986f\u793a\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-77990","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/77990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=77990"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/77990\/revisions"}],"predecessor-version":[{"id":77991,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/77990\/revisions\/77991"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=77990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=77990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=77990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}