Link to home
Start Free TrialLog in
Avatar of gauravflame
gauravflame

asked on

Cursor

Below code doesn't work

================================================
DECLARE
  empnum  tablename.empno%TYPE;
  name    tablename.ename%TYPE;
  TYPE cursor_var IS REF CURSOR;
  myCursorVar cursor_var;
BEGIN
  OPEN myCursorVar FOR SELECT empno,ename FROM tablename;
 
  for x IN myCursorVar LOOP
      DBMS_OUTPUT.PUT_LINE(x.empnum|| '  '|| x.name|| ' rowcount is ' || myCursorVar%ROWCOUNT);
 END LOOP;
 CLOSE myCursorVar;
=======================

but I change the
" for loop under BEGIN structure with below mention LOOP and END LOOP , it is working" --

LOOP
    FETCH myCursorVar INTO empnum,name;
    EXIT WHEN myCursorVar%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(name||'  '||empnum||' rowcount is '||
      myCursorVar%ROWCOUNT);
  END LOOP;


Question :: why it is not working with FOR loop ? or I am doing any mistakes

SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Sujith
Sujith
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial