I'm starting with PL/SQL, this is my first Procedure and i've trouble to make it work.
i've problem (think) with cursor. If you look my code are four comments; i've tested these four Update, but only one work! and i'm sure that two SELECT work, because if i send wrong parameter in input the select don't give a result.
of the four comments, I want that works:
UPDATE partecipa
SET punti= somma
WHERE ( (nomesquadra= nomesquadr) AND
(nometorneo= nometorn));
If there are other errors (also logical) please tell me. I would like to improve.
Thank you all for the answers
my procedure:
create or replace PROCEDURE calcola_giorn (giornata IN INTEGER) IS
-- si tenga presente che in realtà giornata=idPartita
somma NUMBER;
idcal NUMBER;
nometorn VARCHAR2(100);
idformaz NUMBER;
nomesquadr VARCHAR2(100);
CURSOR formazioni_di_giornata IS
SELECT id, nomesquadra FROM formazione where idpartita= giornata;
CURSOR giocatori_di_giornata IS
SELECT votogiocatore FROM schiera WHERE idformazione= idformaz;
Begin
SELECT idcalendario
INTO idcal
FROM partita
WHERE id= giornata;
SELECT nometorneo
INTO nometorn
FROM calendario
WHERE id= idcal;
FOR tupla_formazione IN formazioni_di_giornata LOOP
somma:=0;
FETCH formazioni_di_giornata INTO idformaz, nomesquadr;
FOR tupla_giocatore IN giocatori_di_giornata LOOP
somma:= somma + tupla_giocatore.votogiocatore;
/*DON'T WORK*/-- UPDATE partecipa SET punti= 123;
END LOOP;
/*WORK*/-- UPDATE partecipa SET punti= 12;
/*DON'T WORK*/-- UPDATE partecipa SET punti= 123 WHERE ( (nomesquadra= nomesquadr) AND (nometorneo= nometorn));
/*DON'T WORK*/-- UPDATE partecipa SET punti= somma WHERE ( (nomesquadra= nomesquadr) AND (nometorneo= nometorn));
END LOOP;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001, 'An error was encountered - ' ||
SQLCODE||' -ERROR- '||SQLERRM);
END;