-->

02 October 2020

PL/SQL For Loop Cursor

  Asp.Net CS By Example       02 October 2020
 PL/SQL For Loop Cursor 
    The Loop Cursor is the best cursor ever. It is most frequently used cursor. For this cursor no need to follow cursor steps means no need to declare,open, fetch and close for this cursor.


 Examples :-  
 declare
     cursor cur_emp is select  emp_sal  from  emp; 
 begin
    for i in cur_emp 
    loop        
        dbms_output.put_line( i.emp_sal );
    end loop;
 end;



 More Examples for For Loop Cursor:-  
 begin
    for i in (select empno,ename,job from emp where deptno=&tdeptno) 
    loop        
        dbms_output.put_line( i.ename||','||i.empno||','||i.job);
    end loop;
 end;


 begin
    for i in (select * from emp )
    loop        
        if i.deptno=1 then
            update emp_cur set sal=nvl(i.sal,0)+500 where empno=i.empno; 
        elsif i.deptno=2 then
            update emp_cur set sal=nvl(i.sal,0)+1000 where empno=i.empno;
        end if;
        commit;
    end loop;
 end;
logoblog

Thanks for reading PL/SQL For Loop Cursor

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.