This
cursor is helpful when we need to
execute
the same
query for different
value of
parameter.
Examples :-
declare
cursor cur_emp (l_deptno number)
is select emp_sal from emp where deptno=l_deptno;
l_emp_sal emp.emp_sal%type;
begin
open cur_emp(15);
loop
fetch cur_emp into l_emp_sal;
exit when cur_emp%notfound;
dbms_output.put_line( l_emp_sal);
end loop; ;
dbms_output.put_line('Processed records:-'||cur_emp%rowcount);
close cur_emp;
end;
declare
cursor cur_emp (l_deptno emp.deptno%type,l_job emp.job%type ) is
select emp_sal from emp where deptno=l_deptno and job=l_job;
l_emp_sal emp.emp_sal%type;
begin
open cur_emp(&dpt,&ajob);
loop
fetch cur_emp into l_emp_sal;
exit when cur_emp%notfound;
dbms_output.put_line( l_emp_sal);
end loop; ;
dbms_output.put_line('Processed records:-'||cur_emp%rowcount);
close cur_emp;
end;
No comments:
Post a Comment
Please do not enter any spam link in the comment box.