Results 1 to 3 of 3

Thread: Cursor for loop

  1. #1
    Contributing Member
    Join Date
    Mar 2008
    Answers
    66

    Cursor for loop

    Can We use implicit cursor attributes like %rowcount in cursor for loop?
    Can anyone give one example?


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Cursor for loop

    Quote Originally Posted by babi_geek View Post
    can we use implicit cursor attributes like %rowcount in cursor for loop? can anyone give one example?
    We can use cursor attributes in cursor for loop.

    Create or replace procedure test_proc as
    cursor c1 is
    select sal
    from emp;

    v_avgsal number;
    v_totalsal number :=0;
    v_count number ;

    begin

    for v_cur in c1
    loop

    v_totalsal := v_totalsal + v_cur.sal;
    v_count := c1%rowcount;

    end loop;

    v_avgsal := round ( (v_totalsal / v_count),0);
    dbms_output.put_line('average salary of employees is ' || v_avgsal);
    end;
    /

    sql> set serveroutput on;
    sql> execute test_proc();

    average salary of employees is 2100


  3. #3
    Contributing Member
    Join Date
    Sep 2007
    Answers
    35

    Re: Cursor for loop

    yes we can use corsor attributes in cursor for loop.

    eg:

    declare
    cursor c1 is select * from emp where deptno=10;
    m number(2);
    begin
    for i in c1
    loop
    m:=c1%rowcount;
    end loop;
    dbms_output.put_line('no of rows effected='||m);
    end;
    /
    SQL> @ test2
    no of rows effected=3

    PL/SQL procedure successfully completed.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact