nel database ho una tabella CLIENTI con chiave NUMEROTESSERA e una tabella PRESTITI e sto cercando di creare una procedura in pl/sql che, per ogni cliente, conti nella tabella PRESTITI quanti voci ci sono con il codice di quel cliente e, se sono più di 2, aggiorna un campo della tabella CLIENTI con la data attuale...

ho scritto questo ma non funziona, c'è qualche errore nel blocco if ma non so come risolvere... qualcuno può aiutarmi?

codice:
create or replace procedure ASSEGNA_SCONTI as
begin
  for i in (select NUMEROTESSERA from CLIENTI where SCONTO='no') loop
	if ((select count(*) from AFFITTI where CODICECLIENTE = i.NUMEROTESSERA)>2) then 
	  	(update CLIENTI set SCONTOATTIVODAL = SYSDATE where NUMEROTESSERA=i.NUMEROTESSERA) exit;
	end if;
  end loop;
commit;
end;