I'm trying to do a procedure with the following mysql block:
DECLARE done INT DEFAULT FALSE;
DECLARE v_id INT;
DECLARE R CURSOR FOR
SELECT id
,nome
FROM pessoa d
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN R;
read_loop: LOOP
FETCH R INTO v_id;
IF done THEN
LEAVE read_loop;
END IF;
SELECT DATE_FORMAT(previsao,'%d/%m/%Y') as doba_dt_previsao
,usuario_id
FROM documentos
WHERE doc_pess_id = (
SELECT MAX(doc_ID) ID
FROM DOCUMENTOS
WHERE doc_pess_id = v_id
)
AND docu_quitr IS NULL
AND previsao < DATE(NOW())
END LOOP;
CLOSE R;
I would like to know if you have only select values from within the loop, in a single select.
Because I understand that, every time it runs the loop it will do the select, would you like to know if it has to save those values from the loop in a variable so afterwards I show?
I do not know if it would be correct to give a select of a cursor
Create another cursor within the loop to display?
It's because I searched, I do not know if I researched correctly, but I did not find it.