How can Oracle combine multiple columns into one row?

You can use the LISTAGG function in Oracle to concatenate multiple columns into one row. This function combines the values of multiple columns into a single string, and allows you to specify a delimiter.

For example, suppose you have a table named “employee” with three columns: id, name, and department. You can use the following statement to concatenate the values of these three columns into one row:

SELECT id, LISTAGG(name || ', ' || department, ', ') WITHIN GROUP (ORDER BY id) AS combined_info
FROM employee
GROUP BY id;

In this example, we are using the LISTAGG function to concatenate the values of the name and department columns together, separated by a comma, and sorted according to the id column. Finally, we use the GROUP BY clause to group the results by id.

Leave a Reply 0

Your email address will not be published. Required fields are marked *