How can multiple rows be merged into one column in Oracle?
You can use the LISTAGG function in Oracle to merge values from multiple rows into one row. Here is an example:
SELECT deptno, LISTAGG(ename, ', ') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp
GROUP BY deptno;
In the example above, we selected the department number (deptno) and employee name (ename) from the employee table (emp), then used the LISTAGG function to merge the names of employees in the same department into a single string separated by commas. Finally, we grouped the results by department number using the GROUP BY clause.