Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

soterd procedure cursor infinite loop

Status
Not open for further replies.

tsalinas

Programmer
Mar 6, 2009
4
US
I'm using Pervasive Database v8.7 and I have the following stored
procedure that It doesn't work and goes into a endless loop.

Is it that this database doesn't support nested cursors?

thank you.

CREATE PROCEDURE populate_test() AS
BEGIN

DECLARE :v_parent CHAR(20);
DECLARE :v_part1 CHAR(20);

declare x cursor for
select distinct parent from BOM_MSTR;

open x;

delete from BOM_TEST3;

INSLOOP:
LOOP

IF SQLSTATE = '02000' THEN
LEAVE INSLOOP;
END IF;

FETCH NEXT FROM x INTO
:v_parent;

declare y cursor for
select distinct part from BOM_MSTR
where parent=:v_parent;

open y;
INSLOOP2:
LOOP
IF SQLSTATE = '02000' THEN
LEAVE INSLOOP2;
END IF;


FETCH NEXT FROM y INTO
:v_part1;

START TRANSACTION;

INSERT INTO BOM_TEST3 (Parent,Part,lvl)
values :)v_parent,:v_part1,1);
COMMIT WORK;

END LOOP;
CLOSE y;

END LOOP;
CLOSE x;
END
 
I would suggest adding some Print statements so you know which part is actually causing the loop.
Also, how many records are you dealing with? It's possible that it's not stuck in a loop but is just taking longer than expected. How long have you left it running?

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
It getting stuck in the second loop in the insert statement, and it keeps inserting the same records over and over again. the table has about 7000 records
 
Aparently the exit condition is never met and the fetch keeps returning the last record..

IF SQLSTATE = '02000' THEN
LEAVE INSLOOP2;
END IF;

is not working.
 
yes..with millions of records...it keeps inserting the last record. The fetch from the second cursor returns that last record all the time and it never leaves that loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top