Assuming table EMP has three columns (deptno, ename and salary). How would i write a for loop that would look like this and be able to access the items in the LISTAGG function
BEGIN
FOR rec IN (SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp
WHERE deptNo = 'XYZ'
GROUP BY deptno)
LOOP
Update EMP
set salary = 10000
WHERE ename in (THE ITEMS IN THE LISTAGG)
FOR EACH (ITEM RETURNED IN THE LISTAGG)
DO SOMETHING
END;
END LOOP;
END;
Basically i want to know two things,
- How can i refer to all the items in returned by the listagg function (See UPDATE statement inside for loop)
- How can i iterate through each of the items returned by teh listagg function. See INNER FOR LOOP.
- Would the syntax for the above also work for WM_CONCAT and COLLECT functions.
Thanks in advance.