Can We use implicit cursor attributes like %rowcount in cursor for loop?
Can anyone give one example?
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
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.