APPLIES TO:
Oracle Database - Enterprise Edition - Version 10.1.0.2 to 18.5.0.0.0 [Release 10.1 to 18]
Information in this document applies to any platform.
GOAL
From Oracle 12.1.0.1 onwards WM_CONCAT function is disabled. We need to use LISTAGG Function.
EXAMPLE:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> SELECT WM_CONCAT(DISTINCT TYPE) from v$parameter; WM_CONCAT(DISTINCTTYPE)
SQL>
Connected to:
SQL> SELECT WM_CONCAT(DISTINCT TYPE) from v$parameter;
SQL> |
SOLUTION
Why LISTAGG?
LISTAGG is superior to WM_CONCAT. It is fewer latches than wm_concat, latches are lightweight locks that impact the scalability, the more latches we do, the less the scalability is.
LISTAGG does not support the "DISTINCT" option. But it does exclude null values. So, you need to take care of the distinct values yourself before applying LISTAGG.
EXAMPLE:
SQL> drop table t purge; Table dropped. SQL>
Table created. --
SQL>
1 row created. SQL> insert into t values (1,'Name2'); 1 row created. SQL> insert into t values (1,'Name3'); 1 row created. SQL>
SQL> insert into t values (2,'Name1'); 1 row created. SQL> insert into t values (2,'Name2'); 1 row created. SQL> insert into t values (2,'Name1');
SQL> insert into t values (2,'Name2'); 1 row created. SQL> insert into t values (2,'Name4'); 1 row created. SQL>
1 row selected. SQL>
1 row selected.
|
More Information:
From the doc: Oracle Database 12.2 New Features
"Enhanced LISTAGG Functionality
LISTAGG aggregates the values of a column by concatenating them into a single string. New functionality has been added for managing situations where the length of the concatenated string is too long.
Developers can now control the process for managing overflowing LISTAGG aggregates. This increases the productivity and flexibility of this aggregation function."