We have referred below link with similar issue but still not able to get desired output,
How to use a variable from a cursor in the select statement of another cursor in pl/sql
**PL/SQL Block:**
begin
for d in (select listagg(''''||deptno||'''',',')
within group(order by deptno) deptno from dept)
loop
for e in (select * from emp where deptno=d.deptno)
loop
dbms_output.put_line( 'Employee ' || e.ename ||
' in department ' || d.dname );
end loop;
end loop;
end;
/
We are not able to generate message with above pl/sql block.