wm_concat and listagg usage, merge row data

Method one wn_concat() function

1. Combine the data with the same Name in the following figure into one, and the value of NO should be displayed like C.1, C.2

2. The operation to achieve this effect is as follows, first group the value of Name (group by), and then combine the value of NO with the wm_concat() function (note: remember to use to_char(), otherwise the data will not be displayed)

 

Method 2 listagg() function

 

The first step is consistent with the above

Use the listagg() function to add within group(order by s.no), they are one

 

If it doesn't work, execute the following script:

  1. SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmctab.plb;  
  2. SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmaggrs.plb  
  3. SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmaggrb.plb

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326226677&siteId=291194637