Oracle LISTAGG Function Guide

The Oracle Listagg function is used to concatenate multiple rows of data into a single string, joining them together with a specified delimiter. Its syntax is as follows:

LISTAGG(column_name, delimiter) WITHIN GROUP (ORDER BY column_name)

In which, column_name represents the name of the column to be merged, delimiter is the separator to be used, and the ORDER BY clause is optional, used to specify the sorting order of the merged results.

For example, if we have a table that includes fields for names and ages, we can use the Listagg function to concatenate all the names into one string like this:

SELECT LISTAGG(name, ', ') WITHIN GROUP (ORDER BY name) AS all_names
FROM table_name;

This will return a string containing all names, separated by commas and spaces.

bannerAds