Home » SQL & PL/SQL » SQL & PL/SQL » How to fetch record from Cursor and store them in memory -URGENT
How to fetch record from Cursor and store them in memory -URGENT [message #37572] Thu, 14 February 2002 11:36 Go to next message
UmaSund
Messages: 22
Registered: February 2002
Junior Member
Hi

My cursor is returning 9 rows of data. Now I need to grab the value from first row and store in memory, grab the second value and store in memeory.
Then i need to do calculation between the two stored value.

How do i store them in memory. The rows have no primary key.

A sample sample codeis greatly appreciated.

Thanks
-UmaSUND
Re: How to fetch record from Cursor and store them in memory -URGENT [message #37574 is a reply to message #37572] Thu, 14 February 2002 12:02 Go to previous messageGo to next message
Suresh Vemulapalli
Messages: 624
Registered: August 2000
Senior Member
declare
cursor c1 is select ename from emp;
lename varchar2(20);
begin
for crec in c1 loop
if lename is not null then
-- do calculations with lename and crec.ename
end if;
lename :=crec.ename;
end loop;
Re: How to fetch record from Cursor and store them in memory -URGENT [message #37580 is a reply to message #37574] Thu, 14 February 2002 15:38 Go to previous messageGo to next message
UmaSund
Messages: 22
Registered: February 2002
Junior Member
Thanks Suresh

My problem is that I want to calculate the difference between the first row and second row of the same column which is in the cursor.

So how can i store the data of the first record and the second record from the cursor.

Thanks
-UmaSund
Re: How to fetch record from Cursor and store them in memory -URGENT [message #37583 is a reply to message #37574] Thu, 14 February 2002 18:33 Go to previous message
Somu
Messages: 24
Registered: February 2000
Junior Member
Hi,

Try the following Sample Code.

create or replace procedure date1 is
wip_ent1 number(10);
oper_seq1 number(5);
lst_upd1 date;
qrc1 number(10);
wip_ent2 number(10);
oper_seq2 number(5);
lst_upd2 date;
qrc2 number(10);
date_dif number(5);
first1 number(1);

cursor c1 is select wip_entity_id,operation_seq_num,last_update_date,
qrc
from tab1;
begin
first1 := 1;
open c1;
loop
fetch c1 into wip_ent1, oper_seq1, lst_upd1, qrc1;
exit when c1%notfound ;

if first1 = 1 then
dbms_output.put_line('Entity Opr Seq No Days Diff QRC Date1
Date2');

dbms_output.put_line('===========================================================');
wip_ent2 := wip_ent1;
oper_seq2 := oper_seq1;
lst_upd2 := lst_upd1;
qrc2 := qrc1;
first1 := 0;
else
dbms_output.put_line(to_char(wip_ent2,'999999')||'
'||to_char(oper_seq2,'999999')||' '||to_char(trunc(lst_upd2 - lst_upd1),'9999')||'
'||to_char(qrc2,'9999')||' '||lst_upd2||' '||lst_upd1);
wip_ent2 := wip_ent1;
oper_seq2 := oper_seq1;
lst_upd2 := lst_upd1;
qrc2 := qrc1;
end if;
end loop;
end;

Sample Output.
----------------

Entity Opr Seq No Days Diff QRC Date1 Date2
===========================================================
1 1 1 10 04-FEB-02 03-FEB-02
1 1 2 20 03-FEB-02 01-FEB-02
2 3 0 22 01-FEB-02 01-FEB-02
2 4 2 25 01-FEB-02 30-JAN-02
2 4 10 26 30-JAN-02 20-JAN-02
Previous Topic: Re: Dropping table in Oracle if they exist
Next Topic: Procedure to drop tables
Goto Forum:
  


Current Time: Fri Sep 24 16:49:03 CDT 2021