Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Just to let you know...what a great site you have. I posted a pretty generic question yesterday and have had 8 responses already, anyway thanks again and keep up the good work..."

Geography

Where in the world do Tek-Tips members come from?
tsalinas (Programmer)
6 Mar 09 13:10
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
mirtheil (Programmer)
6 Mar 09 13:21
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
http://www.mirtheil.com

tsalinas (Programmer)
6 Mar 09 13:24
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
tsalinas (Programmer)
6 Mar 09 13:56
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.
mirtheil (Programmer)
6 Mar 09 14:07
And is BOM_TEST3 filling up?  
How long have you let it run?  

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

tsalinas (Programmer)
6 Mar 09 14:10
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close