---
title: "wmsys.wm_concat"
author: "Soft_Development"
date: "2012-07-24T14:40:47Z"
tags: []
categories: ["数据库"]
slug: "wmsys-wm-concat"
draft: false
lastmod: "2012-07-24T14:40:47Z"
id: 1605577
url: "https://soft-development.iteye.com/blog/1605577"
---

wmsys.wm\_co[nc](http://www.linuxso.com/command/nc.html) at

Definition:  
The Oracle PL/SQL  **WM\_CONCAT**   function is u[sed](http://www.linuxso.com/command/sed.html) to aggregate data from a number of rows into a single row, giving a list of data associated with a specific value. In effect, it cross-tabulates a comma delimited list.

Note that  **WM\_CONCAT**   is undocumented and un[su](http://www.linuxso.com/command/su.html) pported by Oracle, meaning it should not be used in pro[du](http://www.linuxso.com/command/du.html) ction systems. The  LISTAGG  function, [which](http://www.linuxso.com/command/which.html) can produce the same output as **WM\_CONCAT**   is both documented and supported by Oracle.

 

例子：

 

> ```
> select t1.main_id

,
       to_char(wmsys.wm_concat

(t1.send_id || '||' || t2.realn

ame || '||' ||
                               t2.IMG_PATH)) sendidlist
  from LCMS_SEND_USER t1, LCMS_USER_STUD t2
 group by t1.main_id;
> ```

结果：

![](http://www.linuxso.com/uploads/allimg/120425/1014203204-0.png)

 

 

网络中也有这样使用：

下面只是收藏：

> ```
> SQL> select id,wmsys.wm_concat(name) over (order by id) name from idtable;

        ID NAME
---------- --------------------------------------------------------------------------------
        10 ab,bc,cd


        10 ab,bc,cd
        10 ab,bc,cd
        20 ab,bc,cd,hi,ij,mn
        20 ab,bc,cd,hi,ij,mn
        20 ab,bc,cd,hi,ij,mn

6 rows selected
> ```

 

> ```
> SQL> select id,wmsys.wm_concat(name) over (order by id,name) name from idtable;

        ID NAME
---------- --------------------------------------------------------------------------------
        10 ab
        10 ab,bc
        10 ab,bc,cd
        20 ab,bc,cd,hi
        20 ab,bc,cd,hi,ij
        20 ab,bc,cd,hi,ij,mn

6 rows selected

个人觉得这个用法比较有趣.

SQL> select id,wmsys.wm_concat(name) over (partition by id) name from idtable;

        ID NAME
---------- --------------------------------------------------------------------------------
        10 ab,bc,cd
        10 ab,bc,cd
        10 ab,bc,cd
        20 hi,ij,mn
        20 hi,ij,mn
        20 hi,ij,mn

6 rows selected

SQL> select id,wmsys.wm_concat(name) over (partition by id,name) name from idtable;

        ID NAME
---------- --------------------------------------------------------------------------------
        10 ab
        10 bc
        10 cd
        20 hi
        20 ij
        20 mn

6 rows selected
> ```