WM_CONCAT

Syntax

WM_CONCAT
(
  expr  IN text
)
RETURNS text;

Overview

This aggregation function combines multiple text values in a group into a single string. It sequentially combines the input text values to create a single string.

The inner workings are as follows:

  • If the input value is NULL, exclude it from the aggregation.

  • When the first value is entered, a new state (string buffer) is created.

  • If a value is subsequently entered, the existing string is appended with a default delimiter (comma), followed by the value.

  • When aggregation is complete, the accumulated string is returned as the final result.

Parameters

Parameter
Description

expr

text type: the text value to aggregate.

null values are excluded from aggregation.

Example

# Test table
create table employees ( first_name varchar, last_name varchar );

INSERT INTO employees (first_name, last_name) VALUES
('John', 'Doe'),
('Jane', 'Smith'),
('Michael', 'Johnson'),
('Emily', 'Davis'),
('David', 'Wilson'),
('Sarah', 'Brown'),
('James', 'Taylor'),
('Jessica', 'Martinez'),
('Daniel', 'Anderson'),
('Laura', 'Thomas');


# test 1
select oracle.wm_concat(last_name) from employees ;

                              wm_concat                               
----------------------------------------------------------------------
 Doe,Smith,Johnson,Davis,Wilson,Brown,Taylor,Martinez,Anderson,Thomas
(1 row)

# test 2
select oracle.wm_concat(first_name) from employees ;

                           wm_concat                            
----------------------------------------------------------------
 John,Jane,Michael,Emily,David,Sarah,James,Jessica,Daniel,Laura
(1 row)

Last updated