If you want to get range data/rows such as range
= 1+1+2=4 means id 1 to 3(3 rows) or range =1+1+2+3=7 means id = 1to 4
(4 rows)
ID NAME RANGE
---------- --------------------
----------
1
feroz 1
2 farid 1
3 foysal 2
4 test 3
5 azad 1
6 jamal 2
6 rows selected.
create or replace procedure
loop_back(num number) as
a number:=0;
v_id number;
v_name varchar2(100);
v_range number;
cursor c1 is select id,name,range
from test order by id;
begin
open c1;
fetch c1 into
v_id,v_name,v_range;
while c1%found and a<num loop
insert into test2 values(v_id,v_name,v_range);
fetch c1 into
v_id,v_name,v_range;
a:=a+v_range;
end loop;
close c1;
commit;
end;
exec loop_back(4);
output :
ID NAME RANGE
---------- --------------------
----------
1
feroz 1
2 farid 1
3 foysal 2
exec loop_back(7);
output :
ID NAME RANGE
---------- --------------------
----------
1
feroz 1
2 farid 1
3 foysal 2
4 test 3
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন