title: In Oracle PL/SQL, how do i iterate/access a collection containing the result of LISTAGG function
body: <p>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</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Basically i want to know two things, </p>
  
  <ul>
  <li>How can i refer to all the items in returned by the listagg function (See UPDATE statement inside for loop)</li>
  <li>How can i iterate through each of the items returned by teh listagg function. See INNER FOR LOOP. </li>
  <li>Would the syntax for the above also work for WM_CONCAT and COLLECT functions. </li>
  </ul>
  
  <p>Thanks in advance. </p>