2

I have the problem with my nested cursors in MySQL.

My second cursor only advances 1 single record of the first courses and then shows me message indicating. Below is a sample of the response from my Mysql Workbeanch.

OPEN queryLegalArticleSource;
    queryLegalArticleSource_LOOP : LOOP
        -- PARSED VARS
        FETCH queryLegalArticleSource INTO configTypeArticleTypeTwo;  
        -- ************************************
        -- VALIDATE PROCESS noMoreRows
        -- ************************************
        IF noMoreRowsTwo = 1 THEN
            CLOSE queryLegalArticleSource;
            LEAVE queryLegalArticleSource_LOOP;
        END IF;                        
        SELECT legalBodyId, companyIdSource, configTypeArticleTypeTwo, noMoreRowsTwo;
    END LOOP queryLegalArticleSource_LOOP;     
CLOSE queryLegalArticleSource;

My response

If I comment the FETCH line

-- FETCH queryLegalArticleSource INTO configTypeArticleTypeTwo;  

Get all the results, but I do not have the variable I need.

enter image description here

Check if any cursor was closing it before, but apparently I have everything right.

Does anyone have any idea?

1

You are trying to close the cursor after it is already closed. If no more rows=1 is true, it closes the cursor. Then exists the loop. Then tries to close the cursor again.

  • Finally it was not directly the problem, but it helped me better understand the algorithms of cursors in mysql – Jonathan Ramírez May 3 '17 at 12:28
0

Get rid of the cursor. Swap the ordering, then use LIMIT 1 on the SELECT.

(Caveat: I am guessing at a lot of things because of missing declarations, etc.)

(Please consider using shorter 'names'; it is hard to see the flow for the verbose names.)

  • Self explaining names are so much nicer... – Mike Lischke May 3 '17 at 7:18
  • I think the same, better explanatory name – Jonathan Ramírez May 3 '17 at 12:27
  • The problem si solved! Ty Guys! – Jonathan Ramírez May 5 '17 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.