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?

2 Answers 2

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.

1
  • Finally it was not directly the problem, but it helped me better understand the algorithms of cursors in mysql May 3, 2017 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.)

3
  • Self explaining names are so much nicer... May 3, 2017 at 7:18
  • I think the same, better explanatory name May 3, 2017 at 12:27
  • The problem si solved! Ty Guys! May 5, 2017 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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