Declaring Cursor inside a loop
Fabian Eschrich
info at faesch.de
Wed Aug 20 06:26:01 CDT 2008
Hi,
I am working on my first procedure.
Inside a loop I have to check if a table already has a record for a specific date, so I redeclare a cursor with every loop.
But valentina tells me
13:25:28 Kernel error: 0x56501. Cursor "vcurDatesum2" is opened already.
This is my code inside the loop.
LOOP
BEGIN
print 'Begin Loop';
FETCH NEXT vcurTransactions INTO vTdate,vNet,vCustomer_id;
BEGIN
DECLARE vcurDatesum2 CURSOR FOR select VAL1 from statistics where val1 = datetrunc(vTdate,'day') AND addressid = vCustomer_id;
DECLARE vVal1 VARCHAR(255);
OPEN vcurDatesum2;
FETCH FIRST vcurDatesum2 INTO vVal1;
close vcurDatesum2;
Print 'Fetched first Datesum';
update statistics set val2 = val2 + vNet where val1 = datetrunc(vTdate,'day') AND addressid = vCustomer_id;
EXCEPTION WHEN ERR_CURSOR_WRONG_POSITION THEN
PRINT 'Exception in Loop with Datesum2';
INSERT INTO statistics (addressid,val1,val2) VALUES (vCustomer_id,datetrunc(vTdate,'day'),vNet);
End
EXCEPTION WHEN ERR_CURSOR_WRONG_POSITION THEN
LEAVE
END
END LOOP
What can I do?
Thanks for your help.
Bye, Fabian
More information about the Valentina
mailing list