MySQL Forums
Forum List  »  Italian

CURSORI MYSQL
Posted by: giovanni grappasonno
Date: December 13, 2016 12:42PM

Buonasera a tutti. Sono nuovo del mondo mysql.
Sto creando una procedura che stampi a video i record di una tabella tramite utilizzando un cursore. So che basterebbe una semplice select ma voglio capire meglio il funzionamento dei cursori.
Il codice che utilizzo è il seguente:

delimiter $$
drop procedure if exists print_row;
create procedure print_row ()
begin
declare v_stop int default 0;
declare n text;
declare c text;
DECLARE cur CURSOR FOR SELECT nome,cognome FROM persone;
declare exit handler for not found set v_stop=1;
open cur;
ciclo: while not v_stop do
fetch cur into n,c;
select n,c;
end while ciclo;
close cur;
end;$$

La tabella in questione è composta da due record. Ad ogni giro il ciclo dovrebbe fare la fetch del record corrente nelle variabili e stamparle. Come mai stampa solo l'ultimo record?
Grazie in anticipo per l'aiuto.

Options: ReplyQuote


Subject
Views
Written By
Posted
CURSORI MYSQL
1088
December 13, 2016 12:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.