{"id":160163,"date":"2024-11-03T20:48:19","date_gmt":"2024-11-03T12:48:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160163\/"},"modified":"2024-11-03T20:48:20","modified_gmt":"2024-11-03T12:48:20","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-listagg","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160163\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase LISTAGG"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-listagg-FyArecYzOw\">OceanBase \u6559\u7a0b\uff1aOceanBase LISTAGG<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u9078\u64c7\u548c\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002OceanBase \u4f5c\u70ba\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684\u5206\u4f48\u5f0f\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u5f37\u5927\u7684\u529f\u80fd\u4f86\u6eff\u8db3\u7528\u6236\u7684\u9700\u6c42\u3002\u5176\u4e2d\uff0cLISTAGG \u51fd\u6578\u662f\u4e00\u500b\u975e\u5e38\u5be6\u7528\u7684\u805a\u5408\u51fd\u6578\uff0c\u80fd\u5920\u5c07\u591a\u884c\u6578\u64da\u5408\u4f75\u70ba\u4e00\u884c\uff0c\u4e26\u4ee5\u7279\u5b9a\u7684\u5206\u9694\u7b26\u9023\u63a5\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e OceanBase \u4e2d\u7684 LISTAGG \u51fd\u6578\uff0c\u4e26\u63d0\u4f9b\u76f8\u95dc\u7684\u4f7f\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-listagg-%e5%87%bd%e6%95%b8%ef%bc%9f-FyArecYzOw\">\u4ec0\u9ebc\u662f LISTAGG \u51fd\u6578\uff1f<\/h2>\n<p>LISTAGG \u51fd\u6578\u662f\u4e00\u7a2e\u805a\u5408\u51fd\u6578\uff0c\u7528\u65bc\u5c07\u591a\u884c\u6578\u64da\u5408\u4f75\u70ba\u4e00\u884c\u3002\u5b83\u901a\u5e38\u7528\u65bc\u5831\u544a\u548c\u6578\u64da\u5206\u6790\u4e2d\uff0c\u80fd\u5920\u5c07\u67d0\u4e00\u5217\u7684\u6240\u6709\u503c\u9023\u63a5\u8d77\u4f86\uff0c\u4e26\u4ee5\u6307\u5b9a\u7684\u5206\u9694\u7b26\u5206\u9694\u3002\u9019\u5728\u9700\u8981\u751f\u6210\u4ee5\u9017\u865f\u3001\u5206\u865f\u6216\u5176\u4ed6\u5b57\u7b26\u5206\u9694\u7684\u5217\u8868\u6642\u7279\u5225\u6709\u7528\u3002<\/p>\n<h2 id=\"listagg-%e5%87%bd%e6%95%b8%e7%9a%84%e8%aa%9e%e6%b3%95-FyArecYzOw\">LISTAGG \u51fd\u6578\u7684\u8a9e\u6cd5<\/h2>\n<pre><code>\nLISTAGG (expression, delimiter) WITHIN GROUP (ORDER BY order_by_expression)\n<\/code><\/pre>\n<ul>\n<li><strong>expression<\/strong>: \u8981\u805a\u5408\u7684\u5217\u6216\u8868\u9054\u5f0f\u3002<\/li>\n<li><strong>delimiter<\/strong>: \u7528\u65bc\u5206\u9694\u6bcf\u500b\u503c\u7684\u5b57\u7b26\u3002<\/li>\n<li><strong>ORDER BY<\/strong>: \u6307\u5b9a\u5408\u4f75\u6642\u7684\u6392\u5e8f\u65b9\u5f0f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-FyArecYzOw\">\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528 LISTAGG \u51fd\u6578\u7684\u793a\u4f8b\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <code>employees<\/code> \u7684\u8868\uff0c\u8a72\u8868\u5305\u542b\u54e1\u5de5\u7684\u59d3\u540d\u548c\u90e8\u9580\u4fe1\u606f\u3002<\/p>\n<pre><code>\nSELECT department,\n       LISTAGG(employee_name, ', ') WITHIN GROUP (ORDER BY employee_name) AS employee_list\nFROM employees\nGROUP BY department;\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u67e5\u8a62\u4e2d\uff0c\u6211\u5011\u5c07\u6839\u64da\u90e8\u9580\u5c0d\u54e1\u5de5\u59d3\u540d\u9032\u884c\u5206\u7d44\uff0c\u4e26\u4f7f\u7528\u9017\u865f\u548c\u7a7a\u683c\u4f5c\u70ba\u5206\u9694\u7b26\uff0c\u751f\u6210\u6bcf\u500b\u90e8\u9580\u7684\u54e1\u5de5\u59d3\u540d\u5217\u8868\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-FyArecYzOw\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528 LISTAGG \u51fd\u6578\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u805a\u5408\u7684\u7d50\u679c\u8d85\u904e\u4e86\u6700\u5927\u9577\u5ea6\uff0c\u5247\u6703\u5f15\u767c\u932f\u8aa4\u3002\u56e0\u6b64\uff0c\u61c9\u8a72\u8003\u616e\u5230\u53ef\u80fd\u7684\u6578\u64da\u91cf\u3002<\/li>\n<li>\u5728\u4f7f\u7528 ORDER BY \u5b50\u53e5\u6642\uff0c\u5fc5\u9808\u78ba\u4fdd\u6240\u9078\u64c7\u7684\u5217\u5728\u805a\u5408\u51fd\u6578\u4e2d\u662f\u6709\u610f\u7fa9\u7684\u3002<\/li>\n<li>LISTAGG \u51fd\u6578\u7684\u6027\u80fd\u53ef\u80fd\u6703\u53d7\u5230\u6578\u64da\u91cf\u7684\u5f71\u97ff\uff0c\u56e0\u6b64\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\uff0c\u61c9\u9032\u884c\u6027\u80fd\u6e2c\u8a66\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-FyArecYzOw\">\u7d50\u8ad6<\/h2>\n<p>LISTAGG \u51fd\u6578\u5728 OceanBase \u4e2d\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u8f15\u9b06\u5730\u5c07\u591a\u884c\u6578\u64da\u5408\u4f75\u70ba\u4e00\u884c\uff0c\u4e26\u4ee5\u6307\u5b9a\u7684\u5206\u9694\u7b26\u9032\u884c\u5206\u9694\u3002\u901a\u904e\u5408\u7406\u4f7f\u7528\u6b64\u51fd\u6578\uff0c\u7528\u6236\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u9032\u884c\u6578\u64da\u5206\u6790\u548c\u5831\u544a\u751f\u6210\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u6578\u64da\u8655\u7406\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u81f3\u95dc\u91cd\u8981\u3002\u82e5\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u6216\u5176\u4ed6 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u89e3\u6c7a\u65b9\u6848\u611f\u8208\u8da3\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to use OceanBase LISTAGG in this comprehensive tutorial, enhancing your data aggregation skills with practical examples and tips.<\/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-160163","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160163","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=160163"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160163\/revisions"}],"predecessor-version":[{"id":160164,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160163\/revisions\/160164"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}