0

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.

6
  • 2
    If you run the first cursor query on its own you'll see a single string value of a comma-seperated list. No employee matches that entire single string. Why do you want to use multiple loops? Or PL/SQL at all? Commented Aug 6, 2018 at 7:37
  • how Looks you data in a table? what is expected Output? Commented Aug 6, 2018 at 7:37
  • yes, there are multiple dept no but we need to check from comma separated string, if there is at least 1 dept no is matched with dept no in emp table then it should display corresponding emp no and dept no. Commented Aug 6, 2018 at 7:42
  • 1
    I don't understand. Why do you need to check from a comma separated string when you have the original values available? Commented Aug 6, 2018 at 7:44
  • Thanks a lot..got your point which resolve my issue as well. Commented Aug 6, 2018 at 7:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.