Two declared cursor

0

I would like to leave two cursors declared at the beginning of the procedure

DECLARE R CURSOR FOR SELECT C.CODIGO FROM TABELA1;  
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = TRUE;
DECLARE aulas CURSOR FOR    SELECT DISTINCT a.codigo FROM TABELA2;  
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1 = TRUE;

To give two loops, one inside the other

But I'm getting this message:

  

Cursor declaration after handler declaration

OPEN R; -- VAMOS DAR UM LOOP NOS COLABORADORES
    loop0: LOOP
         FETCH R INTO v_codfun; 
            IF done2 THEN
               LEAVE loop0;
            END IF;

            BLOCO2: BEGIN

              OPEN aulas; -- VAMOS DAR UM LOOP NAS AULAS        
                 loop1: LOOP    
                    FETCH aulas INTO v_codaula;  
                    IF done1 THEN
                        LEAVE loop1;
                    END IF;
                        ***
                  END LOOP loop1;   
                CLOSE aulas;        

            END BLOCO2;
    END LOOP ;      
CLOSE R; 
SELECT * FROM temp1;                        
    
asked by anonymous 16.08.2018 / 19:50

0 answers