Home » SQL & PL/SQL » SQL & PL/SQL » problem with cursor
problem with cursor [message #219311] Tue, 13 February 2007 23:52 Go to next message
chinmay_uce02
Messages: 11
Registered: January 2007
Junior Member
hi all,

i have a small problem with the following code.

declare
 mgrname varchar2(10);
 begin
 for empcur in (select ename,mgr from emp)
 loop
 select ename into mgrname from emp where empno=empcur.mgr;
 dbms_output.put_line('Ename :'||empcur.ename||'  Mgrname :'||mgrname);
 end loop;
 end;



here i want to get the name of the manager for each employee.

i am getting the following error

SQL> /
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 6


can any one help.
thanks in advance
chinmay

Re: problem with cursor [message #219314 is a reply to message #219311] Wed, 14 February 2007 00:00 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,


BEGIN
FOR REC_EMP IN (SELECT E.ENAME EMP_NAME ,M.ENAME MGR_NAME FROM EMP E,EMP M
WHERE E.MGR=M.EMPNO)
LOOP
DBMS_OUTPUT.PUT_LINE(REC_EMP.EMP_NAME||','||REC_EMP.MGR_NAME);
END LOOP;
END;



regards,
Re: problem with cursor [message #219315 is a reply to message #219311] Wed, 14 February 2007 00:02 Go to previous messageGo to next message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
So why do you need PL/SQL to produce the results?
Re: problem with cursor [message #219317 is a reply to message #219314] Wed, 14 February 2007 00:11 Go to previous message
chinmay_uce02
Messages: 11
Registered: January 2007
Junior Member
dhananjay wrote on Wed, 14 February 2007 00:00
hi,


BEGIN
FOR REC_EMP IN (SELECT E.ENAME EMP_NAME ,M.ENAME MGR_NAME FROM EMP E,EMP M
WHERE E.MGR=M.EMPNO)
LOOP
DBMS_OUTPUT.PUT_LINE(REC_EMP.EMP_NAME||','||REC_EMP.MGR_NAME);
END LOOP;
END;



regards,




thanks a lot
Previous Topic: reference key
Next Topic: Impact of changing Varchar to Varchar2
Goto Forum:
  


Current Time: Mon Dec 05 02:53:31 CST 2016

Total time taken to generate the page: 0.06604 seconds